autobahn.twisted.wamp¶
Classes¶
A WAMP application. The application object provides a simple way of |
|
This class is a convenience tool mainly for development and quick hosting |
|
WAMP application session for Twisted-based applications. |
|
WAMP application session factory for Twisted-based applications. |
|
A WAMP application as a twisted service. |
|
shim that lets us present pep8 API for user-classes to override, |
Module Contents¶
- class Application(prefix=None)[source]¶
Bases:
objectA WAMP application. The application object provides a simple way of creating, debugging and running WAMP application components.
- __call__(config)[source]¶
Factory creating a WAMP application session for the application.
- Parameters:
config (Instance of
autobahn.wamp.types.ComponentConfig) – Component configuration.- Returns:
obj – An object that derives of
autobahn.twisted.wamp.ApplicationSession
- _fire_signal(name, *args, **kwargs)[source]¶
Utility method to call all signal handlers for a given signal.
- Parameters:
name (str) – The signal name.
- register(uri=None)[source]¶
Decorator exposing a function as a remote callable procedure.
The first argument of the decorator should be the URI of the procedure to register under.
- Example:
@app.register('com.myapp.add2') def add2(a, b): return a + b
Above function can then be called remotely over WAMP using the URI com.myapp.add2 the function was registered under.
If no URI is given, the URI is constructed from the application URI prefix and the Python function name.
- Example:
app = Application('com.myapp') # implicit URI will be 'com.myapp.add2' @app.register() def add2(a, b): return a + b
If the function yields (is a co-routine), the @inlineCallbacks decorator will be applied automatically to it.
- Parameters:
uri (unicode) – The URI of the procedure to register under.
- run(url='ws://localhost:8080/ws', realm='realm1', start_reactor=True)[source]¶
Run the application.
- Parameters:
url (unicode) – The URL of the WAMP router to connect to.
realm (unicode) – The realm on the WAMP router to join.
- signal(name)[source]¶
Decorator attaching a function as handler for application signals.
Signals are local events triggered internally and exposed to the developer to be able to react to the application lifecycle.
If the function yield, it will be assumed that it’s an asynchronous coroutine and inlineCallbacks will be applied to it.
Current signals :
- onjoined: Triggered after the application session has joined the
realm on the router and registered/subscribed all procedures and event handlers that were setup via decorators.
onleave: Triggered when the application session leaves the realm.
@app.signal('onjoined') def _(): # do after the app has join a realm
- Parameters:
name (unicode) – The name of the signal to watch.
- subscribe(uri=None)[source]¶
Decorator attaching a function as an event handler.
The first argument of the decorator should be the URI of the topic to subscribe to. If no URI is given, the URI is constructed from the application URI prefix and the Python function name.
If the function yield, it will be assumed that it’s an asynchronous process and inlineCallbacks will be applied to it.
- Example:
@app.subscribe('com.myapp.topic1') def onevent1(x, y): print("got event on topic1", x, y)
- Parameters:
uri (unicode) – The URI of the topic to subscribe to.
- class ApplicationRunner(url: str, realm: str | None = None, extra: Dict[str, Any] | None = None, serializers: List[autobahn.wamp.interfaces.ISerializer] | None = None, ssl: twisted.internet.ssl.CertificateOptions | None = None, proxy: Dict[str, Any] | None = None, headers: Dict[str, Any] | None = None, websocket_options: Dict[str, Any] | None = None, max_retries: int | None = None, initial_retry_delay: float | None = None, max_retry_delay: float | None = None, retry_delay_growth: float | None = None, retry_delay_jitter: float | None = None)[source]¶
Bases:
objectThis class is a convenience tool mainly for development and quick hosting of WAMP application components.
It can host a WAMP application component in a WAMP-over-WebSocket client connecting to a WAMP router.
- run(make, start_reactor: bool = True, auto_reconnect: bool = False, log_level: str = 'info', endpoint: twisted.internet.interfaces.IStreamClientEndpoint | None = None, reactor: twisted.internet.interfaces.IReactorCore | None = None) type(None) | twisted.internet.defer.Deferred[source]¶
Run the application component.
- Parameters:
make – A factory that produces instances of
autobahn.twisted.wamp.ApplicationSessionwhen called with an instance ofautobahn.wamp.types.ComponentConfig.start_reactor – When
True(the default) this method starts the Twisted reactor and doesn’t return until the reactor stops. If there are any problems starting the reactor or connect()-ing, we stop the reactor and raise the exception back to the caller.auto_reconnect
log_level
endpoint
reactor
- Returns:
None is returned, unless you specify
start_reactor=Falsein which case the Deferred that connect() returns is returned; this will callback() with an IProtocol instance, which will actually be an instance ofWampWebSocketClientProtocol
- class ApplicationSession(config: autobahn.wamp.types.ComponentConfig | None = None)[source]¶
Bases:
autobahn.wamp.protocol.ApplicationSessionWAMP application session for Twisted-based applications.
Implements:
- class ApplicationSessionFactory(config=None)[source]¶
Bases:
autobahn.wamp.protocol.ApplicationSessionFactoryWAMP application session factory for Twisted-based applications.
- session: ApplicationSession[source]¶
The application session class this application session factory will use. Defaults to
autobahn.twisted.wamp.ApplicationSession.
- class Service(url, realm, make, extra=None, context_factory=None)[source]¶
Bases:
twisted.application.service.MultiServiceA WAMP application as a twisted service. The application object provides a simple way of creating, debugging and running WAMP application components inside a traditional twisted application
This manages application lifecycle of the wamp connection using startService and stopService Using services also allows to create integration tests that properly terminates their connections
It can host a WAMP application component in a WAMP-over-WebSocket client connecting to a WAMP router.
- class Session(config: autobahn.wamp.types.ComponentConfig | None = None)[source]¶
Bases:
autobahn.wamp.protocol._SessionShimshim that lets us present pep8 API for user-classes to override, but also backwards-compatible for existing code using ApplicationSession “directly”.
NOTE: this is not public or intended for use; you should import either autobahn.asyncio.wamp.Session or autobahn.twisted.wamp.Session depending on which async framework yo’re using.