Session

class

diffusion.session.Session(url, principal='', credentials=None, properties=None)

A client session connected to a Diffusion server or a cluster of servers.

Parameters
  • url (str) WebSockets URL of the Diffusion server to connect to.
  • principal (str, optional) The name of the security principal associated with the session.
  • credentials (Credentials, optional) Security information required to authenticate the connection.

The recommended method is to instantiate this class as an async context manager. Here is a minimal example:

async with diffusion.Session("ws://diffusion.server:8080") as session:
    # do some work with the session

The context manager will make sure that the connection is properly closed at the end of the program. Alternatively, it is possible to open the connection explicitly, which can be useful if the session needs to be passed around, in this case the connection needs to be explicitly closed as well:

session = diffusion.Session("ws://diffusion.server:8080")
await session.connect()
# do some work with the session
await session.close()
Attributes
  • data (dict) Internal data storage.
  • services The ServiceLocator instance responsible for retrieving services.
  • session_id The current session ID.
  • state Returns the current connection state of the session.
Methods
  • close() Closes the session.
  • connect(properties) Connect to the server.
  • ping_server() Send the user ping to the server.
method

connect(properties=None)

Connect to the server.

Parameters
  • properties (dict(str: str), optional) A dict of Diffusion session properties to set and/or update at connection.
method

close()

Closes the session.

method

ping_server()

Send the user ping to the server.

class

diffusion.internal.session.credentials.Credentials(value=b'')

Simple wrapper class to encapsulate server credentials.

Parameters
  • value (str or bytes, optional) value: The value of the credentials.
Attributes
  • password (str) The base64-encoded textual representation of the credentials.
Examples
>>> cred1 = Credentials("bar")
>>> cred1.type
<CredentialsType.PLAIN_PASSWORD: 1>
>>> cred1.password
'AQNiYXI='
>>> tuple(cred1)
(1, b'bar')
>>> cred2 = Credentials(b"bla")
>>> cred2.type
<CredentialsType.CUSTOM: 2>
>>> cred2.password
'AgNibGE='