autobahn.twisted.wamp

Classes

Application

A WAMP application. The application object provides a simple way of

ApplicationRunner

This class is a convenience tool mainly for development and quick hosting

ApplicationSession

WAMP application session for Twisted-based applications.

ApplicationSessionFactory

WAMP application session factory for Twisted-based applications.

Service

A WAMP application as a twisted service.

Session

shim that lets us present pep8 API for user-classes to override,

Module Contents

class Application(prefix=None)[source]

Bases: object

A 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.

_handlers = [][source]
_prefix = None[source]
_procs = [][source]
_signals[source]
log[source]
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.

session = None[source]
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: object

This 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.

_client_service = None[source]
_connect_successes = 0[source]
extra[source]
headers = None[source]
initial_retry_delay = None[source]
log[source]
max_retries = None[source]
max_retry_delay = None[source]
proxy = None[source]
realm = None[source]
retry_delay_growth = None[source]
retry_delay_jitter = None[source]
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.ApplicationSession when called with an instance of autobahn.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=False in which case the Deferred that connect() returns is returned; this will callback() with an IProtocol instance, which will actually be an instance of WampWebSocketClientProtocol

serializers = None[source]
ssl = None[source]
stop()[source]

Stop reconnecting, if auto-reconnecting was enabled.

url[source]
websocket_options = None[source]
class ApplicationSession(config: autobahn.wamp.types.ComponentConfig | None = None)[source]

Bases: autobahn.wamp.protocol.ApplicationSession

WAMP application session for Twisted-based applications.

Implements:

log[source]
class ApplicationSessionFactory(config=None)[source]

Bases: autobahn.wamp.protocol.ApplicationSessionFactory

WAMP application session factory for Twisted-based applications.

log[source]
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.MultiService

A 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.

context_factory = None[source]
extra[source]
factory[source]
make[source]
realm[source]
setupService()[source]

Setup the application component.

url[source]
class Session(config: autobahn.wamp.types.ComponentConfig | None = None)[source]

Bases: autobahn.wamp.protocol._SessionShim

shim 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.

on_connect()[source]
on_disconnect()[source]
on_join(details)[source]
on_leave(details)[source]
on_welcome(welcome_msg)[source]