Python SDK
Connect Python services, workers, and tools to Celeris with asyncio, and sign credentials on trusted servers.
The Python SDK brings Celeris to asyncio programs: backend services, workers, command-line tools, and desktop applications. It behaves like the JavaScript SDK, with Python names and asyncio idioms.
Each channel connection automatically joins a segment named default. Access it with channel.default_segment(). That stream does not need an explicit subscription. Use additional named segments when you need separate topics. Messaging explains the listener and permission setup.
Two packages
useceleris-clientmanages connections, messages, subscriptions, and presence.useceleris-serversigns credentials from your application's access decisions. It runs on trusted servers only.
pip install useceleris-client
pip install useceleris-server
Install the server package only on servers that hold the signing secret. It depends on useceleris-client 1.0.0 or later. The client does not include signing facilities.
Both packages support Python 3.10 to 3.14 and include type information (py.typed). The client depends on pydantic, websockets, and typing-extensions.
Follow the guides
- Connection and lifecycle: obtain credentials, connect, observe state, recover, and clean up.
- Messaging: subscribe, publish, receive, and understand delivery.
- Payload formats: text, validated JSON, and custom serializers.
- Presence: list connections and watch presence events.
- Errors and troubleshooting: handle failures where the SDK reports them.
- Server-side usage: sign credentials, and connect from a trusted backend.
Read Reconnection and Recovery for the shared explanation of retries, replay, and application reconciliation. Exact signatures live in the Python client API and Python server API.
asyncio in brief
- Run the SDK inside an event loop, for example with
asyncio.run(main()). Use a channel only from that loop's thread. - Listeners are plain functions. The SDK calls them synchronously, in registration order, when events arrive. The SDK refuses
async deflisteners. Start a task from a listener for asynchronous work. - Each connection does its network work on its own thread. A listener that blocks your event loop does not stop the heartbeat pings.
- Cancellation comes from asyncio itself. When you cancel the task that awaits
connect(),publish(), orpresence_list(), that operation stops and the await raisesCancelledError.
Work with SDK values
Every number is an int. Timestamps delivered with messages, notices, and presence are Unix milliseconds. Convert one with datetime.fromtimestamp(timestamp / 1000, tz=timezone.utc). Payloads are bytes.
Vocabulary
| Term | Meaning |
|---|---|
| Channel reference | Name of a communication space inside your application |
| Channel | Owns one connection once connected |
| Segment | Named stream carried over that channel's socket |
| Listener | Your function for an event. Registration returns a removal function |
| Subscription | Held interest in messages or presence. Release it with cancel() |
| Credential provider | Your coroutine that obtains fresh signed access for each connection attempt |