Autobahn|Python: WebSocket & WAMP for Real-Time Python Applications
This repository profile is provided by osrepos.com, an open source repository discovery platform.

Summary
Autobahn|Python is a robust open-source library providing WebSocket and WAMP implementations for Python 3.11+. It enables developers to build real-time applications with bidirectional messaging, remote procedure calls, and publish-subscribe patterns, seamlessly integrating with Twisted and asyncio frameworks.
Repository Information
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Introduction
Autobahn|Python is a powerful open-source library that provides robust implementations of the WebSocket Protocol and the Web Application Messaging Protocol (WAMP) for Python 3.11+. Designed to run on both Twisted and asyncio frameworks, it empowers developers to build high-performance, real-time applications. With Autobahn|Python, you can easily create clients and servers capable of bidirectional messaging, asynchronous Remote Procedure Calls (RPC), and Publish & Subscribe (PubSub) patterns, making it ideal for modern web and application communication.
Installation
Getting started with Autobahn|Python is straightforward using pip.
To install the core library:
python -m pip install autobahn
For additional functionalities, such as advanced compression, encryption, or WAMP authentication, you can install optional dependencies:
- Twisted support:
pip install autobahn[twisted] - Compression (Brotli recommended):
pip install autobahn[compress] - Encryption & WAMP-cryptosign:
pip install autobahn[encryption] - WAMP-SCRAM authentication:
pip install autobahn[scram] - Native Vector Extensions (NVX) for acceleration:
pip install autobahn[nvx]
Examples
Autobahn|Python simplifies the creation of real-time components. Here are two illustrative examples:
WebSocket Echo Server
This server echoes back any WebSocket message it receives:
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))
More examples and boilerplate code for running servers can be found in the official documentation.
WAMP Application Component
This example demonstrates a WAMP component performing subscribe, publish, register, and call actions:
from autobahn.twisted.wamp import ApplicationSession
# or: from autobahn.asyncio.wamp import ApplicationSession
from twisted.internet.defer import inlineCallbacks
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))
For details on running WAMP application components and routers, refer to the documentation.
Why Use Autobahn|Python?
Autobahn|Python stands out for its comprehensive feature set and commitment to performance and standards:
- Dual Framework Support: Seamlessly integrates with both Twisted and asyncio, offering flexibility for Python developers.
- Full Protocol Implementation: Provides complete, standards-compliant implementations of WebSocket (RFC6455) and WAMP.
- High Performance: Features a fully asynchronous design, optional SIMD-accelerated native vector extensions (NVX) for WebSocket operations, and optimized serializers.
- Best-in-Class Conformance: Achieves 100% strict passes with the Autobahn Testsuite, ensuring reliability and interoperability.
- Advanced Features: Supports WebSocket compression (including Brotli), TLS for secure communication, and various WAMP authentication methods (WAMP-cryptosign, WAMP-SCRAM).
- Robust Packaging: Offers comprehensive binary wheel coverage for CPython and PyPy across major platforms and architectures, ensuring easy installation without system dependencies.
Links
Explore Autobahn|Python further with these official resources:
- Source Code: https://github.com/crossbario/autobahn-python
- Documentation: https://autobahn.readthedocs.io/en/latest/
- WebSocket Examples: https://autobahn.readthedocs.io/en/latest/websocket/examples.html
- WAMP Examples: https://autobahn.readthedocs.io/en/latest/wamp/examples.html
- Community Forum: https://crossbar.discourse.group/
- WAMP Protocol: https://wamp-proto.org/
Source repository
Open the original repository on GitHub.