The repository or configuration that created this release differ from a previous release. View details.
Typed WebSocket APIs for Python. Write one handler per message; Chanx routes, validates, broadcasts and documents it, and generates typed clients from the result. Runs on Django Channels, FastAPI, or any ASGI framework.
Documentation · Django quick start · FastAPI quick start · TypeScript clients · Ready-made kits
Why Chanx
A raw WebSocket endpoint is one receive method that grows forever:
async def receive(self, text_data):
data = json.loads(text_data)
if data.get("action") == "chat":
if "text" not in data.get("payload", {}):
return await self.send(json.dumps({"error": "missing text"}))
... # find the room, loop over connections, send to each
elif data.get("action") == "ping":
...
# no types, no docs, and the frontend guesses the message shapes
With Chanx, each message is a Pydantic model and each handler is a typed method:
@ws_handler(output_type=ChatNotification)
async def handle_chat(self, message: ChatMessage) -> None:
await self.broadcast_message(ChatNotification(payload=message.payload))
From that, Chanx gives you:
- Routing by type. Incoming JSON is dispatched on its
actionfield to the handler whose argument type matches. Noif/elifchains. - Validation. Payloads are checked by Pydantic before your code runs; bad ones get a structured error reply.
- Groups and events. Broadcast to groups, and push messages from HTTP views, tasks or workers through the channel layer (Redis or in-memory).
- AsyncAPI 3.0 docs. A spec and an interactive docs page, generated from your handlers, so the contract the frontend reads is the code that runs.
- Typed clients. Generate a Python client, a TypeScript client with React, Vue, Svelte and Solid bindings via chanx-js, or a Go client via chanx-go.
- Testing and auth. Test communicators for both frameworks, and authenticators that reuse your DRF permission classes on Django.
- Static typing throughout. Checked with mypy and pyright in strict mode, so handler and message mistakes show up in your editor.
Install
pip install "chanx[channels]" # Django Channels
pip install "chanx[fast_channels]" # FastAPI, Starlette and other ASGI frameworks
Python 3.11 to 3.13. Optional extras: chanx[cli] for the client generator,
chanx[client] to run generated Python clients.
Quick start
A room chat on FastAPI in one file. Save it as main.py:
from typing import Literal
from fastapi import FastAPI, Request
from fast_channels.layers import InMemoryChannelLayer, register_channel_layer
from pydantic import BaseModel
from chanx.core.decorators import channel, ws_handler
from chanx.fast_channels import asyncapi_docs, asyncapi_spec_json
from chanx.fast_channels.websocket import AsyncJsonWebsocketConsumer
from chanx.messages.base import BaseMessage
class ChatPayload(BaseModel):
text: str
class ChatMessage(BaseMessage): # client -> server
action: Literal["chat"] = "chat"
payload: ChatPayload
class ChatNotification(BaseMessage): # server -> everyone in the group
action: Literal["chat_notification"] = "chat_notification"
payload: ChatPayload
@channel(name="chat", description="Room chat")
class ChatConsumer(AsyncJsonWebsocketConsumer):
channel_layer_alias = "default"
groups = ["lobby"] # joined on connect
@ws_handler(output_type=ChatNotification)
async def handle_chat(self, message: ChatMessage) -> None:
await self.broadcast_message(ChatNotification(payload=message.payload))
register_channel_layer("default", InMemoryChannelLayer()) # use Redis in production
app = FastAPI()
app.add_websocket_route("/ws/chat", ChatConsumer.as_asgi())
@app.get("/asyncapi")
async def docs(request: Request):
return await asyncapi_docs(request=request, app=app)
@app.get("/asyncapi.json")
async def spec(request: Request):
return await asyncapi_spec_json(request=request, app=app)
Run it with uvicorn main:app, open two connections to ws://localhost:8000/ws/chat,
and send from one:
{"action": "chat", "payload": {"text": "hi"}}
Both receive:
{"action": "chat_notification", "payload": {"text": "hi"}}
A malformed message ({"action": "chat", "payload": {"txt": "hi"}}) never reaches the
handler; the sender gets a validation error instead. The interactive docs are at
http://localhost:8000/asyncapi.
On Django, the consumer is the same class imported from
chanx.channels.websocket, routed with Channels, with docs from
path("asyncapi/", include("chanx.channels.urls")). See the
Django quick start.
Typed clients
Clients are generated from the AsyncAPI spec, so they always match the server.
TypeScript, with chanx-js:
npm install @chanx-js/client
npx @chanx-js/codegen http://localhost:8000/asyncapi.json -o src/generated
import { useChannel } from '@chanx-js/client/react';
import { chat } from './generated';
function Chat() {
const { send } = useChannel(chat);
// `send` only accepts messages the server declares; a typo is a compile error.
return <button onClick={() => send({ action: 'chat', payload: { text: 'hi' } })}>Say hi</button>;
}
Python, with the built-in generator:
pip install "chanx[cli]"
chanx generate-client --schema http://localhost:8000/asyncapi.json --output ./chat_client
Ecosystem
- chanx-js: TypeScript clients for the browser and Node, and a TypeScript server that speaks the same protocol and can share a Redis layer with Python.
- chanx-go: the Go implementation, for net/http, gin, echo and Fiber servers, with a typed Go client generator. Go and Python processes can share one Redis layer.
- chanx-kit: copy-in components built on Chanx (notifications, chat with history, presence, agent streaming, voice), in the spirit of shadcn/ui.
Learn more
- Introduction and comparison with Channels and FastAPI
- Tutorials: Django, FastAPI
- Configuration and API reference
- Changelog
Contributing
Issues and pull requests are welcome. See CONTRIBUTING.md.
License
BSD. See LICENSE.
Metadata
Release files for chanx 2.12.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Change of provenance
The repository or configuration that created these release files differ from that of a previous release.
We recommend inspecting the repository and configuration before proceeding. View details.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chanx-2.12.4.tar.gz | 90.2 kB | With provenance | Details for chanx-2.12.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chanx-2.12.4-py3-none-any.whl | Python 3 | none | any | Details for chanx-2.12.4-py3-none-any.whl |
Total release size: 207.1 kB
Release files / chanx-2.12.4.tar.gz
Change of provenance
This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.
We recommend inspecting the repository and configuration before proceeding. View details.
| Download URL | chanx-2.12.4.tar.gz |
|---|---|
| Size | 90.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5911474a57e50edc920acf0130f15614b8b7296c76fff00569030b238e800c4f
|
|
BLAKE2b-256 checksum How to use checksums |
a5ec0371fe5578a6a8ed9ee725e20129b5b422c2759624de8254960d52a0af32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logRelease files / chanx-2.12.4-py3-none-any.whl
Change of provenance
This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.
We recommend inspecting the repository and configuration before proceeding. View details.
| Download URL | chanx-2.12.4-py3-none-any.whl |
|---|---|
| Size | 116.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
819c4a810915614b5046a5186893d2b8dddaa75ca7dd3030730722c116ffd1b9
|
|
BLAKE2b-256 checksum How to use checksums |
8d768b63b860ae994030296751ebaeb9f8884b66886b836f472c73d5970e56c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logSecurity for chanx 2.12.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Change of provenance
The repository and configuration that created this release differ from a previous release.
While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.
Repository
- Removed 2.12.3 github.com/huynguyengl99/chanx
- Added 2.12.4 github.com/chanx-dev/chanx
Attestation for chanx-2.12.4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.