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(); no explicit subscription is needed for that stream. Use additional named segments when you need separate topics.
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 --pre useceleris-client
pip install --pre useceleris-server
Install the server package only where the signing secret may live. It depends on the client; the client never includes signing facilities.
Both packages support Python 3.10 to 3.14 and ship type information (py.typed). The client depends on pydantic, websockets and typing-extensions.
Follow the guides
- Connecting 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 they are reported.
- Server-side usage: sign credentials, and connect from a trusted backend.
Read Reconnection and Recovery for 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()), and use a channel only from that loop's thread. - Listeners are plain functions, called synchronously in registration order as events arrive.
async deflisteners are refused; start a task from a listener for asynchronous work. - Cancellation is asyncio's own. Cancelling the task awaiting
connect(),publish()orpresence_list()abandons that operation and raisesCancelledError.
Working 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 app |
| Channel | Owns one connection once connected |
| Segment | Named stream carried over that channel's socket |
| Listener | Your function for an event; registration returns a function removing it |
| Subscription | Held interest in messages or presence; release it with cancel() |
| Credential provider | Your coroutine that obtains fresh signed access for each connection attempt |