# Generated Python Client

Auto-generated type-safe Python client for Centrifugo WebSocket RPC.

## Installation

```bash
pip install -r requirements.txt
```

## Usage

### Basic Usage

```python
import asyncio
from client import CentrifugoRPCClient, APIClient
{% if models %}from models import {{ models[0] if models else 'YourModel' }}
{% endif %}

async def main():
    # Create RPC client
    rpc = CentrifugoRPCClient(
        url='ws://localhost:8000/connection/websocket',
        token='your-jwt-token',
        user_id='user-123'
    )

    # Connect
    await rpc.connect()

    # Create API client
    api = APIClient(rpc)

    try:
        # Call RPC methods
{% if methods %}
{% for method in methods %}
        result = await api.{{ method.name_python }}(params)
        print(result)
{% endfor %}
{% else %}
        # result = await api.some_method(params)
{% endif %}

    finally:
        # Disconnect
        await rpc.disconnect()

# Run
asyncio.run(main())
```

### With Context Manager

```python
async def main():
    async with CentrifugoRPCClient(
        url='ws://localhost:8000/connection/websocket',
        token='your-jwt-token',
        user_id='user-123'
    ) as rpc:
        api = APIClient(rpc)
        result = await api.some_method(params)
        print(result)

asyncio.run(main())
```

## Generated Models

{% if models %}
Available Pydantic models:
{% for model_name in models %}
- `{{ model_name }}`
{% endfor %}
{% else %}
No models generated.
{% endif %}

## Generated Methods

{% if methods %}
Available RPC methods:
{% for method in methods %}
- `{{ method.name_python }}()` - {{ method.docstring.split('\n')[0] if method.docstring else 'No description' }}
{% endfor %}
{% else %}
No methods generated.
{% endif %}

## Type Safety

All methods are fully type-safe:
- Parameters validated with Pydantic
- Return types checked at runtime
- IDE autocomplete support
- mypy compatible

## Error Handling

```python
from asyncio import TimeoutError

try:
    result = await api.some_method(params)
except TimeoutError:
    print("RPC call timed out")
except Exception as e:
    print(f"RPC error: {e}")
```

## Configuration

### Custom Timeout

```python
rpc = CentrifugoRPCClient(
    url='ws://localhost:8000/connection/websocket',
    token='your-jwt-token',
    user_id='user-123',
    timeout=60.0  # 60 seconds
)
```

---

**Generated by django_cfg.apps.centrifugo.codegen**
