> 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/getting-started/first-message/python.md).

# Python

Send your first **1:1 realtime text message** after connecting over WebSocket. This example assumes you completed [**First connection**](https://dnotifier.gitbook.io/product-docs/getting-started/first-connection/python.md).

## Complete example

```python
import asyncio
from dnotifier import DNotifier

MY_USER_ID = "user-alice"
PEER_USER_ID = "user-bob"

async def on_connected(notifier: DNotifier):
    print(f"Connected as {MY_USER_ID}")
    await notifier.send(
        sender_id=MY_USER_ID,
        receiver_id=PEER_USER_ID,
        data={"type": "text", "text": "Hello from DNotifier!"},
    )
    print(f"Message sent to {PEER_USER_ID}")

async def main():
    notifier = DNotifier(
        app_id="your-app-id",
        secret="your-app-secret",
        transport="ws",
        user_id=MY_USER_ID,
        on_connected=lambda: asyncio.create_task(on_connected(notifier)),
        on_message=lambda msg: print(f"[{msg.metadata.sender}] {msg.payload.to_json()}"),
        on_disconnected=lambda code=None, reason=None: print(f"Disconnected: {reason}"),
    )
    await notifier.connect()
    await asyncio.sleep(3600)  # keep alive for incoming messages

asyncio.run(main())
```

Replace credentials with your dashboard values or environment variables.

Run:

```bash
python send_first_message.py
```

## Send after connect (decoupled)

```python
await notifier.connect()

await notifier.send(
    sender_id="user-alice",
    receiver_id="user-bob",
    data={"type": "text", "text": "Hello from DNotifier!"},
    save_history=True,  # default — set False to skip chat history persistence
)
```

## Echo test (two processes)

**Process 1 — bob listens:**

```python
import asyncio
from dnotifier import DNotifier

async def main():
    bob = DNotifier(
        app_id="your-app-id",
        secret="your-app-secret",
        transport="ws",
        user_id="user-bob",
        on_connected=lambda: print("Bob is online"),
        on_message=lambda msg: print(f"Bob received: {msg.payload.to_json()}"),
    )
    await bob.connect()
    await asyncio.sleep(3600)

asyncio.run(main())
```

**Process 2 — alice sends:** use the complete example at the top of this page.

Expected on bob's console:

```
Bob received: {'type': 'text', 'text': 'Hello from DNotifier!'}
```

## Troubleshooting

| Issue                                              | Check                                            |
| -------------------------------------------------- | ------------------------------------------------ |
| `RuntimeError: Not connected`                      | Await `connect()` before `send()`                |
| Receiver gets nothing                              | Receiver must use same `app_id` and be connected |
| `ValueError: receiver_id or receiver_ids required` | Pass `receiver_id` or `receiver_ids`             |
| Auth OK but no delivery                            | Use `transport="ws"`, not `"http"`               |

## Learn more

* [**Understanding messages**](https://dnotifier.gitbook.io/product-docs/getting-started/understanding-messages.md)
* [**Send & receive text — Python**](https://dnotifier.gitbook.io/product-docs/realtime-communication/send-and-receive/python.md)
