Module autobahn.twisted¶
Autobahn Twisted specific classes. These are used when Twisted is run as the underlying networking framework.
Component¶
The component API provides a high-level funcional style method of defining and running WAMP components including authentication configuration
-
class
autobahn.twisted.component.Component(main=None, transports=None, config=None, realm=u'default', extra=None, authentication=None, session_factory=None, is_fatal=None)[source]¶ A component establishes a transport and attached a session to a realm using the transport for communication.
The transports a component tries to use can be configured, as well as the auto-reconnect strategy.
Parameters: - main (callable taking 2 args: reactor, ISession) – After a transport has been connected and a session
has been established and joined to a realm, this (async)
procedure will be run until it finishes – which signals that
the component has run to completion. In this case, it usually
doesn’t make sense to use the
on_*kwargs. If you do not pass a main() procedure, the session will not be closed (unless you arrange for .leave() to be called). - transports (None or unicode or list of dicts) –
Transport configurations for creating transports. Each transport can be a WAMP URL, or a dict containing the following configuration keys:
type(optional):websocket(default) orrawsocketurl: the router URLendpoint(optional, derived from URL if not provided):type: “tcp” or “unix”host,port: only for TCPpath: only for unixtimeout: in secondstls:Trueor (under Twisted) antwisted.internet.ssl.IOpenSSLClientComponentCreatorinstance (such as returned fromtwisted.internet.ssl.optionsForClientTLS) orCertificateOptionsinstance.
- realm (unicode) – the realm to join
- authentication (dict mapping auth_type to dict) – configuration of authenticators
- session_factory (callable) – if None,
ApplicationSessionis used, otherwise a callable taking a singleconfigargument that is used to create a new ApplicationSession instance. - is_fatal (callable taking one arg, or None) – a callable taking a single argument, an
Exceptioninstance. The callable should returnTrueif this error is “fatal”, meaning we should not try connecting to the current transport again. The default behavior (on None) is to always returnFalse
-
session_factory¶ The factory of the session we will instantiate.
alias of
Session
- main (callable taking 2 args: reactor, ISession) – After a transport has been connected and a session
has been established and joined to a realm, this (async)
procedure will be run until it finishes – which signals that
the component has run to completion. In this case, it usually
doesn’t make sense to use the
-
autobahn.twisted.component.run(components, log_level='info')[source]¶ High-level API to run a series of components.
This will only return once all the components have stopped (including, possibly, after all re-connections have failed if you have re-connections enabled). Under the hood, this calls
twisted.internet.reactor.run()– if you wish to manage the reactor loop yourself, use theautobahn.twisted.component.Component.start()method to start each component yourself.Parameters:
WebSocket Protocols and Factories¶
Classes for WebSocket clients and servers using Twisted.
-
class
autobahn.twisted.websocket.WebSocketServerProtocol[source]¶ Base class for Twisted-based WebSocket server protocols.
Implements
autobahn.websocket.interfaces.IWebSocketChannel.
-
class
autobahn.twisted.websocket.WebSocketClientProtocol[source]¶ Base class for Twisted-based WebSocket client protocols.
Implements
autobahn.websocket.interfaces.IWebSocketChannel.
-
class
autobahn.twisted.websocket.WebSocketServerFactory(*args, **kwargs)[source]¶ Base class for Twisted-based WebSocket server factories.
Implements
autobahn.websocket.interfaces.IWebSocketServerChannelFactoryNote
In addition to all arguments to the constructor of
autobahn.websocket.interfaces.IWebSocketServerChannelFactory(), you can supply areactorkeyword argument to specify the Twisted reactor to be used.
-
class
autobahn.twisted.websocket.WebSocketClientFactory(*args, **kwargs)[source]¶ Base class for Twisted-based WebSocket client factories.
Implements
autobahn.websocket.interfaces.IWebSocketClientChannelFactoryNote
In addition to all arguments to the constructor of
autobahn.websocket.interfaces.IWebSocketClientChannelFactory(), you can supply areactorkeyword argument to specify the Twisted reactor to be used.
WAMP-over-WebSocket Protocols and Factories¶
Classes for WAMP-WebSocket clients and servers using Twisted.
-
class
autobahn.twisted.websocket.WampWebSocketServerProtocol[source]¶ Twisted-based WAMP-over-WebSocket server protocol.
Implements:
-
class
autobahn.twisted.websocket.WampWebSocketClientProtocol[source]¶ Twisted-based WAMP-over-WebSocket client protocol.
Implements:
-
class
autobahn.twisted.websocket.WampWebSocketServerFactory(factory, *args, **kwargs)[source]¶ Twisted-based WAMP-over-WebSocket server protocol factory.
Parameters: - factory (callable) – A callable that produces instances that implement
autobahn.wamp.interfaces.ITransportHandler - serializers (list of objects implementing
autobahn.wamp.interfaces.ISerializer) – A list of WAMP serializers to use (orNonefor all available serializers).
-
protocol¶ alias of
WampWebSocketServerProtocol
- factory (callable) – A callable that produces instances that implement
-
class
autobahn.twisted.websocket.WampWebSocketClientFactory(factory, *args, **kwargs)[source]¶ Twisted-based WAMP-over-WebSocket client protocol factory.
Parameters: - factory (callable) – A callable that produces instances that implement
autobahn.wamp.interfaces.ITransportHandler - serializer (object implementing
autobahn.wamp.interfaces.ISerializer) – The WAMP serializer to use (orNonefor “best” serializer, chosen as the first serializer available from this list: CBOR, MessagePack, UBJSON, JSON).
-
protocol¶ alias of
WampWebSocketClientProtocol
- factory (callable) – A callable that produces instances that implement
WAMP-over-RawSocket Protocols and Factories¶
Classes for WAMP-RawSocket clients and servers using Twisted.
-
class
autobahn.twisted.rawsocket.WampRawSocketServerProtocol[source]¶ Twisted-based WAMP-over-RawSocket server protocol.
Implements:
-
class
autobahn.twisted.rawsocket.WampRawSocketClientProtocol[source]¶ Twisted-based WAMP-over-RawSocket client protocol.
Implements:
-
class
autobahn.twisted.rawsocket.WampRawSocketServerFactory(factory, serializers=None)[source]¶ Twisted-based WAMP-over-RawSocket server protocol factory.
Parameters: - factory (callable) – A callable that produces instances that implement
autobahn.wamp.interfaces.ITransportHandler - serializers (list of objects implementing
autobahn.wamp.interfaces.ISerializer) – A list of WAMP serializers to use (orNonefor all available serializers).
-
protocol¶ alias of
WampRawSocketServerProtocol
- factory (callable) – A callable that produces instances that implement
-
class
autobahn.twisted.rawsocket.WampRawSocketClientFactory(factory, serializer=None)[source]¶ Twisted-based WAMP-over-RawSocket client protocol factory.
Parameters: - factory (callable) – A callable that produces instances that implement
autobahn.wamp.interfaces.ITransportHandler - serializer (object implementing
autobahn.wamp.interfaces.ISerializer) – The WAMP serializer to use (orNonefor “best” serializer, chosen as the first serializer available from this list: CBOR, MessagePack, UBJSON, JSON).
-
protocol¶ alias of
WampRawSocketClientProtocol
- factory (callable) – A callable that produces instances that implement
WAMP Sessions¶
Classes for WAMP sessions using Twisted.
-
class
autobahn.twisted.wamp.ApplicationSession(config=None)[source]¶ WAMP application session for Twisted-based applications.
Implements:
Implements
autobahn.wamp.interfaces.ISession()
-
class
autobahn.twisted.wamp.ApplicationRunner(url, realm=None, extra=None, serializers=None, ssl=None, proxy=None, headers=None, max_retries=None, initial_retry_delay=None, max_retry_delay=None, retry_delay_growth=None, retry_delay_jitter=None)[source]¶ 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.
Parameters: - url (str) – The WebSocket URL of the WAMP router to connect to (e.g. ws://somehost.com:8090/somepath)
- realm (str) – The WAMP realm to join the application session to.
- extra (dict) – Optional extra configuration to forward to the application component.
- serializers (list) – A list of WAMP serializers to use (or None for default serializers).
Serializers must implement
autobahn.wamp.interfaces.ISerializer. - ssl (
twisted.internet.ssl.CertificateOptions) – (Optional). If specified this should be an instance suitable to pass assslContextFactorytotwisted.internet.endpoints.SSL4ClientEndpoint`such astwisted.internet.ssl.CertificateOptions. Leaving it asNonewill use the result of calling Twisted’stwisted.internet.ssl.platformTrust()which tries to use your distribution’s CA certificates. - proxy (dict or None) – Explicit proxy server to use; a dict with
hostandportkeys - headers (dict) – Additional headers to send (only applies to WAMP-over-WebSocket).
- max_retries (int) – Maximum number of reconnection attempts. Unlimited if set to -1.
- initial_retry_delay (float) – Initial delay for reconnection attempt in seconds (Default: 1.0s).
- max_retry_delay (float) – Maximum delay for reconnection attempts in seconds (Default: 60s).
- retry_delay_growth (float) – The growth factor applied to the retry delay between reconnection attempts (Default 1.5).
- retry_delay_jitter (float) – A 0-argument callable that introduces nose into the delay. (Default random.random)
-
run(make, start_reactor=True, auto_reconnect=False, log_level='info')[source]¶ Run the application component.
Parameters: - make (callable) – 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.
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- make (callable) – A factory that produces instances of