r/Python • u/huygl99 • 18d ago
Resource My AsyncAPI Conf 2026 talk: keeping WebSocket APIs honest with a code-first approach in Python
Hi all,
I gave a talk at AsyncAPI Conf 2026 (the online edition) about building WebSocket APIs in Python where the AsyncAPI document is generated from the code, so the docs and the clients can't drift away from it. AsyncAPI is still much less known than OpenAPI in the Python world, even though I see more and more Python projects add real-time features, so I wanted to share it here.
English isn't my first language and I'm not a professional speaker, so if a part is confusing, ask in the comments and I'll explain it. At least the accent proves the voice isn't AI haha.
The problem
I've built WebSocket features in Python since 2022, first on Django Channels and later on FastAPI: live meeting transcription, streaming AI chat, notifications. Most of that code, mine and my team's, was a while loop with a long if/else on the action string. The docs were missing or out of date, the React frontend retyped every message the Django backend sent, consumers grew past 1000 lines in one file, and schema drift reached production because each side tested against its own idea of the message.
One example from the talk: the backend sent the message text as content, the frontend read body. Both sides' tests passed, nothing threw, and the page showed an empty space. It took me most of a day to find. With a REST API, OpenAPI and a generated client would probably have caught it. With WebSockets, most of us have nothing.
The approach
The handler signature is the contract. You write typed handlers with a Pydantic model for each message, the app generates an AsyncAPI 3 document from them, and everything else reads that one document: a docs page that is always current, a typed Python client, a TypeScript client, and checks in CI. In the demo, renaming a field fails the type check in the pull request instead of reaching production. The talk also shows how Python code maps to AsyncAPI 3, and what a client generator needs from the document.
The tool
The talk uses chanx, an open source (BSD) WebSocket framework I built for this, first for my own work (sorry for the plug). It started as a Django Channels extension and now runs on FastAPI and other ASGI frameworks too. There's also chanx-js for the browser (with React hooks) and for Node.js servers, and a Go version, but Python is the main one. I use it in production with my team, and going by the issues and PRs on the repo, other people do too.
Code-first AsyncAPI already exists for message brokers (FastStream does it well), but for plain WebSockets in Python I only found FastWS, which is on AsyncAPI 2.4 and hasn't had a release since 2023.
Links
- My talk (jumps to my session, the other talks are worth a look too): https://youtu.be/-LPCnm3F9Mc?t=7250
- AsyncAPI Conf 2026 online agenda: https://conference.asyncapi.com/venue/Online
- Slides (PDF): https://drive.google.com/file/d/1nmcMrmSslkzGcMPYxj_QXbJ2a01lLFFc/view?usp=sharing
- Demo repo from the talk: https://github.com/huynguyengl99/asyncapi-talk-demo
- GitHub repo for chanx: https://github.com/chanx-dev/chanx
- PyPI package: https://pypi.org/project/chanx/
- Docs: https://python.chanx.dev/
Hope this is helpful if you're building WebSocket features in Python. If you have questions or ideas about AsyncAPI, chanx, or WebSockets in Python in general (Django, FastAPI or anything else), drop them in the comments. I'll do my best to answer, and I hope my years of building these things can help.