WebSocket & WAMP for Python on Twisted and asyncio.
Quick Links: Source Code - Documentation - WebSocket Examples - WAMP Examples Community: Forum - StackOverflow - Twitter - IRC #autobahn/chat.freenode.net Companion Projects: Autobahn|JS - Autobahn|Cpp - Autobahn|Testsuite - Crossbar.io - WAMP
Autobahn|Python is a subproject of Autobahn and provides open-source implementations of
for Python 3.11+ and running on Twisted and asyncio.
You can use Autobahn|Python to create clients and servers in Python speaking just plain WebSocket or WAMP.
WebSocket allows bidirectional real-time messaging on the Web and beyond, while WAMP adds real-time application communication on top of WebSocket.
WAMP provides asynchronous Remote Procedure Calls and Publish & Subscribe for applications in one protocol running over WebSocket. WAMP is a routed protocol, so you need a WAMP Router to connect your Autobahn|Python based clients. We provide Crossbar.io, but there are other options as well.
Note
Autobahn|Python currently requires Python 3.11 or later. Earlier release lines supported older Python versions: up to version v19.11.2 supported Python 2 and 3.4+, up to version v20.7.1 supported Python 3.5+, and up to version v21.2.1 supported Python 3.6+.
IMPORTANT: A Note on Upcoming Policy Changes Regarding AI-Assisted Content
Up to and including release v25.6.1, this project contains no code or documentation generated with the assistance of AI tools. This version represents the final release under our historical contribution policy. Starting with future versions (after release v25.6.1), our contribution policy will change. Subsequent releases MAY contain code or documentation created with AI assistance.
We urge all users and contributors to review our AI Policy. This document details:
This policy was established following an open community discussion, which you can review on GitHub issue #1663.
We are providing this transparent notice to enable you to make an informed decision. If our new AI policy is incompatible with your own (or your organization's) development practices or risk tolerance, please take this into consideration when deciding whether to upgrade beyond version v25.6.1.
To give you a first impression, here are two examples. We have lot more in the repo.
Here is a simple WebSocket Echo Server that will echo back any WebSocket message received:
from autobahn.twisted.websocket import WebSocketServerProtocol
# or: from autobahn.asyncio.websocket import WebSocketServerProtocol
class MyServerProtocol(WebSocketServerProtocol):
def onConnect(self, request):
print("Client connecting: {}".format(request.peer))
def onOpen(self):
print("WebSocket connection open.")
def onMessage(self, payload, isBinary):
if isBinary:
print("Binary message received: {} bytes".format(len(payload)))
else:
print("Text message received: {}".format(payload.decode('utf8')))
# echo back message verbatim
self.sendMessage(payload, isBinary)
def onClose(self, wasClean, code, reason):
print("WebSocket connection closed: {}".format(reason))
To actually run above server protocol, you need some lines of boilerplate.
Here is a WAMP Application Component that performs all four types of actions that WAMP provides:
call a procedure
from autobahn.twisted.wamp import ApplicationSession
class MyComponent(ApplicationSession):
@inlineCallbacks
def onJoin(self, details):
# 1. subscribe to a topic so we receive events
def onevent(msg):
print("Got event: {}".format(msg))
yield self.subscribe(onevent, 'com.myapp.hello')
# 2. publish an event to a topic
self.publish('com.myapp.hello', 'Hello, world!')
# 3. register a procedure for remote calling
def add2(x, y):
return x + y
self.register(add2, 'com.myapp.add2')
# 4. call a remote procedure
res = yield self.call('com.myapp.add2', 2, 3)
print("Got result: {}".format(res))
Above code will work on Twisted and asyncio by changing a single
line (the base class of MyComponent). To actually run above
application component, you need some lines of
boilerplate
and a
WAMP Router.
The Autobahn|Python OSS project:
: for commercial users, typedef int GmbH (Germany)*, original creator and active maintainer of Autobahn, Crossbar.io and WAMP provides production grade, optimized and supported Docker images based on RHEL 9 and Debian 12, including complete SBOM for both the base system and full Python application run-time environment based on CycloneDX v1.6 in JSON format and as a audit-level PDF/A document fulfilling strict cybersecurity requirements addressing e.g. EU CRA and BSI TR-03183.
Autobahn|Python publishes source distributions and pre-built wheels on PyPI and GitHub Releases. The current release line requires Python 3.11 or later and publishes wheels for CPython 3.11 through 3.14 and PyPy 3.11 across supported Linux, macOS, and Windows targets.
The recommended installation method is:
python -m pip install autobahn
Pip will choose the best matching wheel for your Python implementation, operating system, and CPU architecture. See the wheels inventory for the supported wheel matrix and NVX acceleration notes.
Autobahn runs on both Twisted and asyncio. To select the respective netoworking framework, install flavor:
asyncio: Backwards-compatible no-op. Asyncio is included in the
Python standard library for all supported Python versions.twisted: Install Twisted and Twisted support in AutobahnThe accelerate optional dependency is no longer recommended. Autobahn now includes NVX (Native Vector Extensions), which provides SIMD-accelerated native code for WebSocket operations (XOR masking and UTF-8 validation) using CFFI. See the NVX section below for details.
accelerate~~: Deprecated - Use NVX insteadAutobahn supports multiple WebSocket per-message compression algorithms via the compress optional dependency:
pip install autobahn[compress]
Compression Methods Available:
| Method | Availability | Standard | Implementation | Notes |
|---|---|---|---|---|
| permessage-deflate | Always | RFC 7692 | Python stdlib (zlib) | Standard WebSocket compression |
| permessage-brotli | [compress] |
RFC 7932 | brotli / brotlicffi | Recommended - Best compression ratio |
| permessage-bzip2 | Optional | Non-standard | Python stdlib (bz2) | Requires Python built with libbz2 |
| permessage-snappy | Manual install | Non-standard | python-snappy | Requires separate installation |
Platform-Optimized Brotli Support:
Autobahn includes Brotli compression with full binary wheel coverage optimized for both CPython and PyPy:
Advantages of Brotli: - Superior compression ratio compared to deflate or snappy - Binary wheels for all major platforms (Linux x86_64/ARM64, macOS x86_64/ARM64, Windows x86_64) - IETF standard (RFC 7932) for HTTP compression - Fast decompression suitable for real-time applications - Widely adopted by browsers and CDNs
Resources: - RFC 7932 - Brotli Compressed Data Format - Google Brotli - Official implementation - brotlicffi - CFFI bindings for PyPy - PyPI: brotlicffi - WAMP Brotli Extension Discussion
Note on Snappy:
Snappy compression is available but requ
$ claude mcp add autobahn-python \
-- python -m otcore.mcp_server <graph>