Metadata-Version: 2.3
Name: anzar
Version: 0.2.36
Summary: Add your description here
Author: Hakou Guelfen
Author-email: Hakou Guelfen <hakoudev@gmail.com>
Requires-Dist: openapi-client
Requires-Dist: pydantic[email]>=2.11.7
Requires-Dist: pyyaml>=6.0.2
Requires-Dist: requests>=2.32.5
Requires-Python: >=3.14
Description-Content-Type: text/markdown

# Anzar SDK Documentation

## Install The Python SDK
In a python project run the following command to install the anzar package.
=== "uv"
    ```bash
    $ uv add anzar
    ```
=== "pip"
    ```bash
    # in a virtual env run
    $ pip install anzar
    ```

## Create Anzar Auth Instance
in your main entry file (`main.py` for example),
import `anzar.yml` and parse it as a YAML file
```python title="main.py" linenums="1"
def load_config(path: str) -> AnzarConfig:
    import yaml

    try:
        with open(path, "r") as f:
            data = yaml.safe_load(f)
        return AnzarConfig(**data)
    except Exception as e:
        import sys

        sys.exit("check your configuration file: anzar.yml")
```

import Anzar Auth and create your auth instance
```python title="main.py" hl_lines="6" linenums="1"
# Initialize once at application startup
# The SDK will communicate with your Anzar container at the configured api_url
from anzar import Anzar

config = load_config("anzar.yml")
anzar = Anzar(config, options=None)
```

!!! danger
    Only extend these functionality if you are using **JWT** authentication

    :warning: Implement a secure Storage solution
    ```python linenums="1"
    from anzar.types import SdkOptions, SessionTokens

    def refresh_token(tokens: SessionTokens):
        # store tokens.access, tokens.refresh
    options = SdkOptions(
        get_token=lambda: "AccessToken"
        get_refresh_token=lambda: "RefreshToken"
        on_token_refresh=lambda tokens: refresh_token(tokens),
        ...
    )
    ```
    See [`SessionTokens`](../reference#tokens) for the full type definition.

## Basic Usage
Anzar provides authentication support for email and password.
!!! Notes
    Other methods of authentication will be implemented later

### Sign Up
To sign up a user you need to call the method register with the user's information.
```python
from anzar.types import ApiException, AuthResponse

try:
    data: AuthResponse = anzar.Auth.register({
      "username": "username",
      "email": "user@example.com",
      "password": "password"
    })
    if data.tokens:
        # Store securely the `access`,`refresh` tokens
except ApiException as e:
    print(e.status, e.body)
```
See [`AuthResponse`](../reference#authresponse) for the full type definition.

!!! notes "Notes"
    By default, the users are automatically signed in after they successfully sign up.

    Disabling this behavior will be implemented later

### Sign In
To sign in a user you need to call the method login.
```python
from anzar.types import ApiException, AuthResponse

try:
    data: AuthResponse = anzar.Auth.login({
      "email": "user@example.com",
      "password": "password"
    })
    if data.tokens:
        # Store securely the `access`,`refresh` tokens
except ApiException as e:
    print(e.status, e.body)

