A client session connected to a Diffusion server or a cluster of servers.
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()
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.
Simple wrapper class to encapsulate server credentials.
value(str or bytes, optional) — value: The value of the credentials.
password(str) — The base64-encoded textual representation of the credentials.
>>> 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='