{"id":1917,"library":"autobahn","title":"Autobahn Python","description":"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.","status":"active","version":"25.12.2","language":"en","source_language":"en","source_url":"https://github.com/crossbario/autobahn-python","tags":["websocket","wamp","real-time","networking","asyncio","twisted","rpc","pubsub"],"install":[{"cmd":"pip install autobahn","lang":"bash","label":"Minimal install"},{"cmd":"pip install autobahn[all]","lang":"bash","label":"Full install (includes Twisted, asyncio, encryption, and optional dependencies)"},{"cmd":"pip install autobahn[asyncio,encryption]","lang":"bash","label":"Common asyncio-based install with TLS"},{"cmd":"pip install autobahn[twisted,encryption]","lang":"bash","label":"Common Twisted-based install with TLS"}],"dependencies":[{"reason":"Networking backend for synchronous-like asynchronous programming. Optional, alternatively use asyncio.","package":"Twisted","optional":true},{"reason":"Standard Python asynchronous event loop. Optional, alternatively use Twisted.","package":"asyncio","optional":true},{"reason":"Internal abstraction layer for Twisted and asyncio.","package":"txaio","optional":false},{"reason":"Required for TLS/encryption features (part of 'encryption' extra).","package":"cryptography","optional":true},{"reason":"Required for TLS/encryption features (part of 'encryption' extra).","package":"pyopenssl","optional":true},{"reason":"Required for WAMP-cryptosign authentication (part of 'encryption' extra).","package":"pynacl","optional":true},{"reason":"Required for WAMP-SCRAM authentication (part of 'scram' extra).","package":"argon2-cffi","optional":true}],"imports":[{"symbol":"WebSocketServerProtocol","correct":"from autobahn.asyncio.websocket import WebSocketServerProtocol\n# or: from autobahn.twisted.websocket import WebSocketServerProtocol"},{"symbol":"WebSocketClientProtocol","correct":"from autobahn.asyncio.websocket import WebSocketClientProtocol\n# or: from autobahn.twisted.websocket import WebSocketClientProtocol"},{"symbol":"WebSocketServerFactory","correct":"from autobahn.asyncio.websocket import WebSocketServerFactory\n# or: from autobahn.twisted.websocket import WebSocketServerFactory"},{"symbol":"ApplicationSession","correct":"from autobahn.asyncio.wamp import ApplicationSession\n# or: from autobahn.twisted.wamp import ApplicationSession"},{"note":"Use Component with run() function instead of older ApplicationRunner which lacks features.","wrong":"from autobahn.asyncio.wamp import ApplicationRunner","symbol":"Component","correct":"from autobahn.wamp.component import Component"}],"quickstart":{"code":"import asyncio\nfrom autobahn.asyncio.websocket import WebSocketServerFactory, WebSocketServerProtocol\n\nclass MyServerProtocol(WebSocketServerProtocol):\n    def onConnect(self, request):\n        print(f\"Client connecting: {request.peer}\")\n\n    def onOpen(self):\n        print(\"WebSocket connection open.\")\n\n    def onMessage(self, payload, isBinary):\n        if isBinary:\n            print(f\"Binary message received: {len(payload)} bytes\")\n        else:\n            print(f\"Text message received: {payload.decode('utf8')}\")\n\n        # echo back message verbatim\n        self.sendMessage(payload, isBinary)\n\n    def onClose(self, wasClean, code, reason):\n        print(f\"WebSocket connection closed: {reason} (code={code}, clean={wasClean})\")\n\nasync def main():\n    factory = WebSocketServerFactory(\"ws://127.0.0.1:9000\")\n    factory.protocol = MyServerProtocol\n\n    server = await asyncio.get_event_loop().create_server(factory, '127.0.0.1', 9000)\n    print(\"WebSocket server started on ws://127.0.0.1:9000\")\n\n    try:\n        await server.serve_forever()\n    except KeyboardInterrupt:\n        pass\n    finally:\n        server.close()\n        await server.wait_closed()\n        asyncio.get_event_loop().close()\n\nif __name__ == '__main__':\n    asyncio.run(main())","lang":"python","description":"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."},"warnings":[{"fix":"Ensure your project is running on Python 3.11 or newer.","message":"Autobahn 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.","severity":"breaking","affected_versions":"<25.0.0"},{"fix":"Use `loop = asyncio.new_event_loop(); asyncio.set_event_loop(loop)` at the beginning of the child thread/process execution.","message":"When 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 '...'`.","severity":"gotcha","affected_versions":"All versions using asyncio in multi-threaded/multi-process contexts"},{"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.","message":"WAMP 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.","severity":"gotcha","affected_versions":"All WAMP-related versions"},{"fix":"Replace `from autobahn.util import time_ns` with `from txaio import time_ns`.","message":"The `autobahn.util.time_ns` helper was deprecated in favor of `txaio.time_ns` in version 20.1.3.","severity":"deprecated","affected_versions":"<20.1.3"},{"fix":"Remove `accelerate` from your install variants. NVX is often included in platform-specific binary wheels.","message":"The `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.","severity":"deprecated","affected_versions":">=25.11.1"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}