# Python server SDK

> Zero-dependency synchronous client for Django, FastAPI, Flask, or any Python service.

```sh
pip install radist-server
```

## Constructor

`RadistServerClient(secret_token, *, project_id, api_base_url=..., transport=...)`

| Parameter      | Description                                                                                                                         |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `secret_token` | Your project secret key (`rad_sk_...`).                                                                                             |
| `project_id`   | Your project id, used as the path parameter in API calls.                                                                           |
| `api_base_url` | Optional. Override the default API base URL.                                                                                        |
| `transport`    | Optional. Pluggable HTTP transport callable for custom timeouts, proxies, or mocking. Defaults to a stdlib `urllib` implementation. |

## API surface

| Method                                                            | Returns                 | Description                                                                  |
| ----------------------------------------------------------------- | ----------------------- | ---------------------------------------------------------------------------- |
| `create_p2p_connection(access_control=)`                          | `P2PConnection`         | Creates a two-peer call and returns `call_id` and `call_tokens`.             |
| `create_room()`                                                   | `Room`                  | Creates an SFU room and returns `room_id` and `room_tokens`.                 |
| `mint_connection_token(call_id=, room_id=)`                       | `ConnectionToken`       | Mints an extra participant token for an existing call or room.               |
| `create_space(name=, access_type=, password=)`                    | `SpaceCreated`          | Creates a persistent space with participant and one-time host links.         |
| `list_spaces()` / `get_space(space_id)`                           | `list[Space]` / `Space` | Reads persistent space definitions.                                          |
| `update_space()` / `delete_space()` / `rotate_space_host_token()` | —                       | Updates admission settings, deletes a definition, or replaces its host link. |

## Create a P2P call

```python
from radist_server import RadistServerClient

client = RadistServerClient(
    "rad_sk_your_secret_key",
    project_id="your_project_id",
)

# access_control defaults to "private"
conn = client.create_p2p_connection()
print("call id:", conn.call_id)
print("tokens:", conn.call_tokens)
```

## Access control and extra tokens

```python
# Public — anyone with your public key can join:
conn = client.create_p2p_connection(access_control="public")

# For private calls, mint additional tokens server-side as needed:
token = client.mint_connection_token(call_id=conn.call_id)
print("extra token:", token.connection_token)
```

## Rooms and spaces

```python
room = client.create_room()

space = client.create_space(
    name="Daily standup",
    access_type="password",
    password="shared-secret",
)
print(space.participant_url, space.host_url)
```

## Error handling

```python
from radist_server import RadistServerClient, RadistApiError

try:
    conn = client.create_p2p_connection()
except RadistApiError as e:
    print(f"API error {e.status_code}: {e}")
```
