> 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/dnotifier-class/python.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# Python

Package: `dnotifier`

## Import

```python
from dnotifier import DNotifier, DNotifierMessage, DNotifierPlanLimits
```

Workflow types are exported from the same package:

```python
from dnotifier import (
    DNotifier,
    Workflow,
    WorkflowContext,
    define_agent,
    Agent,
    WorkflowError,
)
```

## Static method

| Method         | Signature                                                              | Returns | Description          |
| -------------- | ---------------------------------------------------------------------- | ------- | -------------------- |
| `define_agent` | `define_agent(name: str, run: Callable, *, provider=None, model=None)` | `Agent` | Create a named agent |

## Instance methods

| Method                        | Signature                                                                                              | Returns                       | Transport        | Description                                 |
| ----------------------------- | ------------------------------------------------------------------------------------------------------ | ----------------------------- | ---------------- | ------------------------------------------- |
| `connect`                     | `async connect()`                                                                                      | `bool`                        | Both             | Authenticate; WebSocket handshake if `ws`   |
| `disconnect`                  | `async disconnect()`                                                                                   | `None`                        | WS               | Close WebSocket, set `is_connected = False` |
| `get_plan_limits`             | `get_plan_limits()`                                                                                    | `DNotifierPlanLimits \| None` | Both             | Plan quotas from last auth                  |
| `send`                        | `async send(sender_id, data, receiver_id=None, receiver_ids=None, save_history=True)`                  | `Any`                         | Both             | Send structured message                     |
| `send_binary`                 | `async send_binary(sender_id, receiver_ids, buffer, msg_type="binary")`                                | `None`                        | WS only          | Send raw bytes                              |
| `send_ai`                     | `async send_ai(sender_id, message, save_history=True, session_id=None, provider=None, model=None)`     | `Any`                         | Both             | AI prompt                                   |
| `fetch_ai_history`            | `async fetch_ai_history(sender_id)`                                                                    | `Any`                         | Both             | Fetch AI history                            |
| `delete_ai_history_message`   | `async delete_ai_history_message(sender_id, message_id)`                                               | `Any`                         | Both             | Delete AI history entry                     |
| `fetch_chat_history`          | `async fetch_chat_history(sender_id, receiver_ids)`                                                    | `Any`                         | Both             | Request chat history                        |
| `delete_chat_history_message` | `async delete_chat_history_message(sender_id, message_id)`                                             | `Any`                         | Both             | Delete chat history entry                   |
| `search`                      | `async search(sender_id, query, limit=None, min_similarity=None, filterby_source=None)`                | `Any`                         | Both             | Semantic search                             |
| `add_document`                | `async add_document(sender_id, record_id=None, content=None, text=None, doc_type=None, metadata=None)` | `Any`                         | Both             | Add RAG document                            |
| `update_document`             | `async update_document(...)`                                                                           | `Any`                         | Both             | Update RAG document                         |
| `delete_document`             | `async delete_document(sender_id, record_id=None)`                                                     | `Any`                         | Both             | Delete RAG document                         |
| `list_documents`              | `async list_documents(sender_id, limit=None, offset=None, doc_type=None)`                              | `Any`                         | Both             | List documents                              |
| `get_document`                | `async get_document(sender_id, record_id=None)`                                                        | `Any`                         | Both             | Get one document                            |
| `run_workflow`                | `async run_workflow(workflow, input_data, sender_id=None)`                                             | `dict`                        | HTTP recommended | Run workflow                                |
| `run_agent`                   | `async run_agent(agent, **options)`                                                                    | `dict`                        | HTTP recommended | Standalone tool-agent loop                  |

Also: `notifier.tools`, `notifier.mcp`. See [Tools & MCP — Python](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/tools-and-mcp/python.md). | `send_with_openai` | `async send_with_openai(sender_id, message, **kwargs)` | `Any` | Both | Alias for `send_ai` when AI enabled |

## Instance fields

| Field                | Type          | Description         |
| -------------------- | ------------- | ------------------- |
| `app_id`             | `str`         | Application id      |
| `secret`             | `str`         | Application secret  |
| `user_id`            | `str`         | User id             |
| `url`                | `str`         | WebSocket URL       |
| `is_connected`       | `bool`        | Connection state    |
| `ai_enabled`         | `bool`        | Plan AI flag        |
| `auth_token`         | `str \| None` | Auth token          |
| `message_size_limit` | `int`         | Chunk size in bytes |

## `DNotifierPlanLimits`

Returned by `get_plan_limits()`:

| Field                       | Type          |
| --------------------------- | ------------- |
| `messages_hard_limit`       | `int \| None` |
| `max_ai_requests_per_month` | `int`         |
| `max_ai_words_per_month`    | `int`         |
| `knowledge_base_max_words`  | `int`         |
| `ai_enabled`                | `bool`        |
| `max_users`                 | `int \| None` |
| `max_rows_per_user`         | `int \| None` |

## `run_workflow` return value

| Key           | Type          | Description                        |
| ------------- | ------------- | ---------------------------------- |
| `result`      | `Any`         | Workflow `entry` return value      |
| `state`       | `dict`        | Shared workflow state              |
| `executionId` | `str \| None` | Present when observability enabled |

## Error types

| Error                                                      | When                       |
| ---------------------------------------------------------- | -------------------------- |
| `RuntimeError('Not connected')`                            | Method before `connect()`  |
| `ValueError(...)`                                          | Missing/invalid parameters |
| `RuntimeError('Binary send requires WebSocket transport')` | `send_binary` over HTTP    |
