> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/reference/realtime-methods/python.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# Python

Requires `transport="ws"` for push delivery to `on_message`.

## `send()`

```python
async def send(
    sender_id: str,
    data: Any,
    receiver_id: str | None = None,
    receiver_ids: list[str] | None = None,
    save_history: bool = True,
) -> Any
```

| Parameter      | Type                | Required | Default | Description             |
| -------------- | ------------------- | -------- | ------- | ----------------------- |
| `sender_id`    | `str`               | ✅        | —       | Sender user id          |
| `receiver_id`  | `str \| None`       | \*       | —       | Single recipient        |
| `receiver_ids` | `list[str] \| None` | \*       | —       | Multiple recipients     |
| `data`         | `Any`               | ✅        | —       | JSON-encodable payload  |
| `save_history` | `bool`              | —        | `True`  | Persist to chat history |

**Server metadata:** `type: 'text'`, `code: 200`

**Returns:** RPC response over HTTP; message id over WebSocket for single-chunk sends.

**Chunking:** Large payloads are split when length exceeds `message_size_limit`.

### Example — text

```python
await notifier.send(
    sender_id="user-alice",
    receiver_id="user-bob",
    data={"type": "text", "text": "Hello!"},
)
```

### Example — multiple receivers

```python
await notifier.send(
    sender_id="user-alice",
    receiver_ids=["user-bob", "user-carol"],
    data={"type": "text", "text": "Hello everyone"},
)
```

## `send_binary()`

```python
async def send_binary(
    sender_id: str,
    receiver_ids: list[str],
    buffer: bytes,
    msg_type: str = "binary",
) -> None
```

| Parameter      | Type        | Required | Default    | Description    |
| -------------- | ----------- | -------- | ---------- | -------------- |
| `sender_id`    | `str`       | ✅        | —          | Sender user id |
| `receiver_ids` | `list[str]` | ✅        | —          | Recipients     |
| `buffer`       | `bytes`     | ✅        | —          | Raw bytes      |
| `msg_type`     | `str`       | —        | `"binary"` | Metadata type  |

**Server metadata:** `code: 202`

**Transport:** WebSocket only.

```python
await notifier.send_binary(
    sender_id="user-alice",
    receiver_ids=["user-bob"],
    buffer=bytes([0x00, 0x01, 0x02]),
)
```

## Receiving messages

```python
def on_message(msg):
    body = msg.payload.to_json()
    # msg.metadata.id, .sender, .timestamp, .type
```

## Errors

| Error                                                | Cause          |
| ---------------------------------------------------- | -------------- |
| `RuntimeError('Not connected')`                      | Not connected  |
| `ValueError('sender_id required')`                   | Missing sender |
| `ValueError('receiver_id or receiver_ids required')` | No recipient   |
