Registry / http-networking / autobahn

autobahn

JSON →
library26.7.1pypypi✓ verified 25d ago

Autobahn Python is a networking library that provides open-source implementations of the WebSocket Protocol and the Web Application Messaging Protocol (WAMP). It allows developers to create high-performance, asynchronous WebSocket clients and servers, and WAMP clients and application components, running on either Twisted or asyncio event loops. Currently at version 25.12.2, the project maintains an active development pace with frequent nightly and development builds, alongside regular stable releases.

pip install autobahn
INSTALL
IMPORT
SIG · AUTOBAHN
A
autobahn
http-networkingpythonv26.7.1
Install
6.5s avg
Import
913ms
Disk
87MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v24.4.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
3/4 runs
3/4 runs
py 3.11
3/4 runs
✓ 6.93s
py 3.12
✓ —
✓ 6.33s
py 3.13
✓ —
✓ 6.18s
py 3.9
3/4 runs
3/4 runs
87MB installed
● package 87MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WebSocketServerProtocol
from autobahn.asyncio.websocket import WebSocketServerProtocol # or: from autobahn.twisted.websocket import WebSocketServerProtocol
WebSocketClientProtocol
from autobahn.asyncio.websocket import WebSocketClientProtocol # or: from autobahn.twisted.websocket import WebSocketClientProtocol
WebSocketServerFactory
from autobahn.asyncio.websocket import WebSocketServerFactory # or: from autobahn.twisted.websocket import WebSocketServerFactory
ApplicationSession
from autobahn.asyncio.wamp import ApplicationSession # or: from autobahn.twisted.wamp import ApplicationSession
Component
from autobahn.wamp.component import Component
from autobahn.asyncio.wamp import ApplicationRunner
Use Component with run() function instead of older ApplicationRunner which lacks features.

This quickstart demonstrates a basic WebSocket echo server using the `asyncio` backend. It listens on `ws://127.0.0.1:9000` and echoes back any message it receives. This example can be run directly. For WAMP applications, a separate WAMP Router like Crossbar.io is required.

import asyncio from autobahn.asyncio.websocket import WebSocketServerFactory, WebSocketServerProtocol class MyServerProtocol(WebSocketServerProtocol): def onConnect(self, request): print(f"Client connecting: {request.peer}") def onOpen(self): print("WebSocket connection open.") def onMessage(self, payload, isBinary): if isBinary: print(f"Binary message received: {len(payload)} bytes") else: print(f"Text message received: {payload.decode('utf8')}") # echo back message verbatim self.sendMessage(payload, isBinary) def onClose(self, wasClean, code, reason): print(f"WebSocket connection closed: {reason} (code={code}, clean={wasClean})") async def main(): factory = WebSocketServerFactory("ws://127.0.0.1:9000") factory.protocol = MyServerProtocol server = await asyncio.get_event_loop().create_server(factory, '127.0.0.1', 9000) print("WebSocket server started on ws://127.0.0.1:9000") try: await server.serve_forever() except KeyboardInterrupt: pass finally: server.close() await server.wait_closed() asyncio.get_event_loop().close() if __name__ == '__main__': asyncio.run(main())
Debug
Known issues
breakingAutobahn Python has dropped support for older Python versions. As of version 25.12.2, it officially requires Python >=3.11. Older versions supported Python 3.7+ (since v21.2.1) and Python 2 up to v19.11.2.
fix
Ensure your project is running on Python 3.11 or newer.
affects: <25.0.0
gotchaWhen using asyncio in child threads or subprocesses (e.g., with `multiprocessing`), you must explicitly create and set a new event loop for each new thread/process on Unix-like systems. If you don't, you'll encounter `AssertionError: There is no current event loop in thread '...'`.
fix
Use `loop = asyncio.new_event_loop(); asyncio.set_event_loop(loop)` at the beginning of the child thread/process execution.
affects: All versions using asyncio in multi-threaded/multi-process contexts
gotchaWAMP clients (both Python and JavaScript) require a WAMP router (e.g., Crossbar.io) to mediate communication. Autobahn provides the client/component library, but not the router itself. WAMP servers should also explicitly set the realm they intend to join.
fix
Run a WAMP router (like Crossbar.io) separately and ensure your WAMP components are configured to connect to it and join the correct realm.
affects: All WAMP-related versions
deprecatedThe `autobahn.util.time_ns` helper was deprecated in favor of `txaio.time_ns` in version 20.1.3.
fix
Replace `from autobahn.util import time_ns` with `from txaio import time_ns`.
affects: <20.1.3
deprecatedThe `accelerate` install variant is no longer recommended. Autobahn now includes NVX (Native Vector Extensions) for SIMD-accelerated WebSocket operations (XOR masking and UTF-8 validation), which leverages CFFI for performance.
fix
Remove `accelerate` from your install variants. NVX is often included in platform-specific binary wheels.
affects: >=25.11.1
Errors
Common errors & fixes
ImportError: cannot import name 'WebSocketClientFactory'
The import path for 'WebSocketClientFactory' changed in Autobahn version 0.7.0.
fix
Use 'from autobahn.twisted.websocket import WebSocketClientFactory' instead.
TypeError: __init__() got an unexpected keyword argument 'standalone'
The 'standalone' argument was removed from 'ApplicationRunner' in Autobahn version 0.7.0.
fix
Remove the 'standalone' argument and connect to an external WAMP router like Crossbar.io.
Unhandled Error Traceback (most recent call last): File "/usr/local/bin/wstest", line 9, in <module> load_entry_point('autobahntestsuite==0.5.5', 'console_scripts', 'wstest')() ...
The 'wstest' tool from Autobahn TestSuite encountered an unhandled error, possibly due to misconfiguration or compatibility issues.
fix
Ensure all dependencies are correctly installed and compatible; check the Autobahn TestSuite documentation for proper setup.
AttributeError: 'Component' object has no attribute 'on'
The 'on' method is not available in the functional 'Component' API of Autobahn.
fix
Use the class-based 'Component' API to handle events with 'on' decorators.
WebSocket opening handshake timeout (peer did not finish the opening handshake in time)
The client attempted to establish a WebSocket connection, but the server did not complete the handshake within the expected time, often due to an overloaded server, incorrect server address/port, or firewall issues.
fix
Verify the server's availability, correct address and port, and ensure no firewalls are blocking the connection. If the server is overloaded, consider optimizing its performance or adjusting the timeout settings on the client if applicable.
Upgrade
Version history
26.7.1latest on PyPI · released Jul 15, 2026
Audit
Dependencies
TwistedoptionalNetworking backend for synchronous-like asynchronous programming. Optional, alternatively use asyncio.
asynciooptionalStandard Python asynchronous event loop. Optional, alternatively use Twisted.
txaiorequiredInternal abstraction layer for Twisted and asyncio.
cryptographyoptionalRequired for TLS/encryption features (part of 'encryption' extra).
pyopenssloptionalRequired for TLS/encryption features (part of 'encryption' extra).
pynacloptionalRequired for WAMP-cryptosign authentication (part of 'encryption' extra).
argon2-cffioptionalRequired for WAMP-SCRAM authentication (part of 'scram' extra).
Agent activity
30 hits · last 30 days
node
24
OpenAI (training)
1
Resources
autobahn — pip install autobahn · libregistry