API Reference¶
Client¶
aiowamp is a client library for the WAMP protocol.
-
exception
aiowamp.
AbortError
(msg)[source]¶ Join abort error.
Parameters: msg ( Abort
) –
-
class
aiowamp.
AuthKeyring
(*methods, auth_id=None)[source]¶ Initialise the keyring.
Parameters: - *methods – Methods to initialise the keyring with.
- auth_id (
Optional
[str
]) – Auth id to use. Defaults toNone
. - methods (
ForwardRef
) –
Raises: ValueError
– - The same auth method type was specified multiple times. - No auth id was specified but one of the methods requires it. - Multiple methods specify the same auth extra key withdiffering values.
-
__init__
(*methods, auth_id=None)[source]¶ Initialise the keyring.
Parameters: - *methods – Methods to initialise the keyring with.
- auth_id (
Optional
[str
]) – Auth id to use. Defaults toNone
. - methods (
ForwardRef
) –
Raises: ValueError
– - The same auth method type was specified multiple times. - No auth id was specified but one of the methods requires it. - Multiple methods specify the same auth extra key withdiffering values.
Return type: None
-
__getitem__
(method)[source]¶ Get the auth method with the given name.
Parameters: method ( str
) – Name of the method to get.Return type: AuthMethodABC
Returns: Auth method stored in the keyring. Raises: KeyError
– If no auth method with the given method exists in the keyring.
-
__iter__
()[source]¶ Get an iterator for the auth method names in the keyring.
Return type: Iterator
[str
]
-
class
aiowamp.
AuthKeyringABC
[source]¶ Abstract keyring for auth methods.
-
__getitem__
(method)[source]¶ Get the auth method with the given name.
Parameters: method ( str
) – Name of the method to get.Return type: AuthMethodABC
Returns: Auth method stored in the keyring. Raises: KeyError
– If no auth method with the given method exists in the keyring.
-
__iter__
()[source]¶ Get an iterator for the auth method names in the keyring.
Return type: Iterator
[str
]
-
-
class
aiowamp.
AuthMethodABC
[source]¶ Abstract auth method.
-
method_name
= None¶ Name of the auth method.
-
auth_extra
¶ Additional auth extras that need to be passed along.
None
indicates that no extras need to be passed.Return type: Optional
[Dict
[str
,ForwardRef
]]
-
authenticate
(challenge)[source]¶ Generate an authenticate message for the challenge.
Parameters: challenge ( Challenge
) – Challenge message to respond to.Return type: Union
[Authenticate
,Abort
]Returns: Either an authenticate message to send to the router or an abort message to indicate that the attempt should be aborted. Raises: Exception
– When something goes wrong during authentication. Should be interpreted the same as an abort message.
-
check_welcome
(welcome)[source]¶ Check the welcome message sent by the router.
Used to perform mutual authentication.
Parameters: welcome ( Welcome
) – Welcome message sent by the router.Raises: aiowamp.AuthError
Return type: None
-
-
exception
aiowamp.
BaseError
[source]¶ Base exception for all WAMP related errors.
You will most likely never encounter this error directly, but its subclasses.
-
class
aiowamp.
BlackWhiteList
(*, excluded_ids=None, excluded_auth_ids=None, excluded_auth_roles=None, eligible_ids=None, eligible_auth_ids=None, eligible_auth_roles=None)[source]¶ Data type for black- and whitelisting subscribers.
BlackWhiteList is quite a mouthful, so let’s use bwlist for short.
If both exclusion and eligible rules are present, the Broker will dispatch events published only to Subscribers that are not explicitly excluded and which are explicitly eligible.
Like
list
, an empty bwlist is falsy (i.e.bool(BlackWhiteList()) is False
).bwlist is also a container (i.e. support
x in bwlist
), it returns whether the given key will receive the event with the current constraints.bwlist will keep the constraint lists in ascending order.
Notes
bwlist assumes that the set of auth ids is distinct from the set of auth roles. If they are not, the checks may return invalid results.
Parameters: Create a new bwlist.
The given iterables are converted into lists, sorted, and duplicates are removed.
Parameters: - excluded_ids (
Optional
[Iterable
[int
]]) – Session IDs to exclude. - excluded_auth_ids (
Optional
[Iterable
[str
]]) – Auth IDs to exclude. - excluded_auth_roles (
Optional
[Iterable
[str
]]) – Auth roles to exclude. - eligible_ids (
Optional
[Iterable
[int
]]) – Eligible session IDs. - eligible_auth_ids (
Optional
[Iterable
[str
]]) – Eligible auth IDs. - eligible_auth_roles (
Optional
[Iterable
[str
]]) – Eligible auth roles.
-
__init__
(*, excluded_ids=None, excluded_auth_ids=None, excluded_auth_roles=None, eligible_ids=None, eligible_auth_ids=None, eligible_auth_roles=None)[source]¶ Create a new bwlist.
The given iterables are converted into lists, sorted, and duplicates are removed.
Parameters: - excluded_ids (
Optional
[Iterable
[int
]]) – Session IDs to exclude. - excluded_auth_ids (
Optional
[Iterable
[str
]]) – Auth IDs to exclude. - excluded_auth_roles (
Optional
[Iterable
[str
]]) – Auth roles to exclude. - eligible_ids (
Optional
[Iterable
[int
]]) – Eligible session IDs. - eligible_auth_ids (
Optional
[Iterable
[str
]]) – Eligible auth IDs. - eligible_auth_roles (
Optional
[Iterable
[str
]]) – Eligible auth roles.
Return type: None
- excluded_ids (
-
excluded_ids
¶ Excluded session ids.
Only subscribers whose session id IS NOT in this list will receive the event.
-
excluded_auth_ids
¶ Excluded auth ids.
-
excluded_auth_roles
¶ Excluded auth roles.
-
eligible_ids
¶ Eligible session ids.
Only subscribers whose session id IS in this list will receive the event.
-
eligible_auth_ids
¶ Eligible auth ids.
-
eligible_auth_roles
¶ Eligible auth roles.
-
__contains__
(receiver)[source]¶ Check if the receiver would receive the event.
Parameters: receiver ( Any
) – Session id, auth id, or auth role to check.Return type: bool
Returns: True
if the receiver is eligible and not excluded,False
otherwise.
-
is_excluded
(receiver)[source]¶ Check if the receiver is excluded.
Parameters: receiver ( Union
[int
,str
]) – Session id, auth id, or auth role to check.Return type: bool
Returns: True
if there is an exclusion list and the receiver is in it,False
otherwise.
-
is_eligible
(receiver)[source]¶ Check if the receiver is eligible.
Parameters: receiver ( Union
[int
,str
]) – Session id, auth id, or auth role to check.Return type: bool
Returns: True
if there is no eligible list or the receiver is in it,False
otherwise.
-
exclude_session_id
(session_id)[source]¶ Add an id to the excluded session ids.
Parameters: session_id ( int
) – Session id to add.Return type: None
-
exclude_auth_id
(auth_id)[source]¶ Add an id to the excluded auth ids.
Parameters: auth_id ( str
) – Auth id to add.Return type: None
-
exclude_auth_role
(auth_role)[source]¶ Add a role to the excluded auth roles.
Parameters: auth_role ( str
) – Auth role to add.Return type: None
-
unexclude
(receiver)[source]¶ Remove a receiver from the excluded receivers.
This is the reverse operations for the “exclude_” methods.
Parameters: receiver ( Union
[int
,str
]) – Receiver to remove.Raises: ValueError
– If the receiver isn’t excluded.Return type: None
-
allow_session_id
(session_id)[source]¶ Add an id to the eligible ids.
Parameters: session_id ( int
) – Session id to addReturn type: None
-
allow_auth_id
(auth_id)[source]¶ Add an id to the eligible auth ids.
Parameters: auth_id ( str
) – Auth id to add.Return type: None
-
allow_auth_role
(auth_role)[source]¶ Add a role to the eligible auth roles.
Parameters: auth_role ( str
) – Auth role to add.Return type: None
-
disallow
(receiver)[source]¶ Remove a receiver from the eligible receivers.
This is the reverse operation for the “allow_” methods.
Parameters: receiver ( Union
[int
,str
]) – Receiver to remove.Raises: ValueError
– If the receiver isn’t eligible.Return type: None
-
to_options
(options=None)[source]¶ Convert the bwlist to WAMP options.
Parameters: options ( Optional
[Dict
[str
,ForwardRef
]]) – Dict to write the options to. If not specified, adict
will be created,Return type: Dict
[str
,ForwardRef
]Returns: WAMP dict containing the constraints from the bwlist. If an argument for options was passed, the return value will be the same instance.
-
classmethod
from_options
(options)[source]¶ Create a bwlist from WAMP options.
Parameters: - options (
Dict
[str
,ForwardRef
]) – WAMP options as returned byto_options
. - cls (
Type
[~T]) –
Return type: ~T
Returns: New bwlist with the constraints from the options.
- options (
- excluded_ids (
-
class
aiowamp.
CRAuth
(secret)[source]¶ Auth method for challenge response authentication.
WAMP Challenge-Response (“WAMP-CRA”) authentication is a simple, secure authentication mechanism using a shared secret. The client and the server share a secret. The secret never travels the wire, hence WAMP-CRA can be used via non-TLS connections. The actual pre-sharing of the secret is outside the scope of the authentication mechanism.
Parameters: secret ( str
) –Initialise the auth method.
Parameters: secret ( str
) – Secret to use.-
__init__
(secret)[source]¶ Initialise the auth method.
Parameters: secret ( str
) – Secret to use.Return type: None
-
auth_extra
¶ Additional auth extras that need to be passed along.
None
indicates that no extras need to be passed.Return type: None
-
pbkdf2_hmac
(salt, key_len, iterations)[source]¶ Derive the token using the pdkdf2 scheme.
Parameters: Return type: Returns: Generated token bytes.
-
secret
¶ Secret to use for authentication.
-
authenticate
(challenge)[source]¶ Generate an authenticate message for the challenge.
Parameters: challenge ( Challenge
) – Challenge message to respond to.Return type: Authenticate
Returns: Either an authenticate message to send to the router or an abort message to indicate that the attempt should be aborted. Raises: Exception
– When something goes wrong during authentication. Should be interpreted the same as an abort message.
-
-
class
aiowamp.
Call
(session, call, *, cancel_mode)[source]¶ Initialise the call.
Note that you normally shouldn’t create an instance yourself, it doesn’t actively listen to incoming messages. It expects relevant messages to be passed to
handle_response
.Parameters: -
__init__
(session, call, *, cancel_mode)[source]¶ Initialise the call.
Note that you normally shouldn’t create an instance yourself, it doesn’t actively listen to incoming messages. It expects relevant messages to be passed to
handle_response
.Parameters: Return type: None
-
session
¶ Session used to send messages.
-
on_progress
(handler)[source]¶ Add a progress handler.
Parameters: handler ( Callable
[[ForwardRef
],Union
[Any
,Awaitable
[Any
]]]) – Handler to call with the progress results.Return type: None
-
kill
(e)[source]¶ Kill the call.
Parameters: e ( Exception
) – Exception to raise when interacting with the call.Return type: None
-
-
class
aiowamp.
CallABC
[source]¶ Represents an ongoing call of a remote procedure.
-
__await__
()[source]¶ Wait for the result of the call.
This is the same as
result
.Returns: An awaitable containing the result.
-
on_progress
(handler)[source]¶ Add a progress handler.
Parameters: handler ( Callable
[[ForwardRef
],Union
[Any
,Awaitable
[Any
]]]) – Handler to call with the progress results.Return type: None
-
__anext__
()[source]¶ Wait for the next progress result.
Returns: Next progress result. Raises: StopAsyncIteration
– If the call has completed.
-
-
class
aiowamp.
Client
(session)[source]¶ Initialise the client.
A client is just a wrapper for a session. It takes full control over the session, so when the client closes so will the session.
Parameters: session ( SessionABC
) – Session to wrap.-
__init__
(session)[source]¶ Initialise the client.
A client is just a wrapper for a session. It takes full control over the session, so when the client closes so will the session.
Parameters: session ( SessionABC
) – Session to wrap.Return type: None
-
session
¶ Session the client is attached to.
-
id_gen
¶ ID generator used to generate the client ids.
-
close
(details=None, *, reason=None)[source]¶ Close the client and the underlying session.
Parameters: Return type: None
-
publish
(topic, *args, kwargs=None, acknowledge=None, blackwhitelist=None, exclude_me=None, disclose_me=None, resource_key=None, options=None)[source]¶ Publish an event to a topic.
Parameters: - topic (
str
) – Topic uri to publish to. - *args – Arguments for the event.
- kwargs (
Optional
[Dict
[str
,ForwardRef
]]) – Keyword arguments for the event. - acknowledge (
Optional
[bool
]) – Whether to wait for the router to acknowledge the event. - blackwhitelist (
Optional
[BlackWhiteList
]) – Black- and whitelisting subscribers. - exclude_me (
Optional
[bool
]) – Whether the client should receive this event. - disclose_me (
Optional
[bool
]) – Whether the client’s identity should be disclosed to subscribers. - resource_key (
Optional
[str
]) – Resource key for sharded subscriptions. - options (
Optional
[Dict
[str
,ForwardRef
]]) – Additional options. - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) –
Return type: None
- topic (
-
register
(procedure, handler, *, disclose_caller=None, match_policy=None, invocation_policy=None, options=None)[source]¶ Register a procedure.
Parameters: - procedure (
str
) – Procedure URI to register. - handler (
Callable
[[ForwardRef
],Union
[Awaitable
[ForwardRef
],AsyncGenerator
[ForwardRef
,None
]]]) – Procedure to call. - disclose_caller (
Optional
[bool
]) – Whether callers’ identities should be disclosed. - match_policy (
Optional
[NewType()
(MatchPolicy
,str
)]) – Match policy for the procedure uri. Can also be specified by passing anaiowamp.URI
with a match policy to the procedure. - invocation_policy (
Optional
[NewType()
(InvocationPolicy
,str
)]) – Invocation policy. - options (
Optional
[Dict
[str
,ForwardRef
]]) – Additional options to pass.
Return type: Returns: The registration id of the registered procedure. Can be used to unregister the procedure.
- procedure (
-
subscribe
(topic, callback, *, match_policy=None, node_key=None, options=None)[source]¶ Subscribe to a topic.
Parameters: - topic (
str
) – Topic uri to subscribe to. - callback (
Callable
[[ForwardRef
],Union
[Any
,Awaitable
[Any
]]]) – Callable to call for each event. - match_policy (
Optional
[NewType()
(MatchPolicy
,str
)]) – Match policy for the uri. Can also be specified by passing anaiowamp.URI
with a match policy. - node_key (
Optional
[str
]) – Node key for sharded subscriptions. - options (
Optional
[Dict
[str
,ForwardRef
]]) – Additional options to pass.
Return type: - topic (
-
unregister
(procedure, registration_id=None)[source]¶ Unregister a procedure.
Parameters: Raises: KeyError
– If no registration for the procedure exists.Return type: None
-
unsubscribe
(topic, subscription_id=None)[source]¶ Unsubscribe from the given topic.
Parameters: Raises: KeyError
– If not subscribed to the topic.Return type: None
-
get_registration_ids
(procedure)[source]¶ Get the ids of the registrations for the given procedure.
Parameters: procedure ( str
) – Procedure to get registration ids for.Return type: Tuple
[int
, …]Returns: Tuple containing the registration ids.
-
call
(procedure, *args, kwargs=None, receive_progress=None, call_timeout=None, cancel_mode=None, disclose_me=None, resource_key=None, options=None)[source]¶ Call a remote procedure.
Parameters: - procedure (
str
) – Procedure uri to call. - *args – Arguments to pass to the call.
- kwargs (
Optional
[Dict
[str
,ForwardRef
]]) – Keyword arguments to pass to the call. - receive_progress (
Optional
[bool
]) – Whether the callee may send progress results. - call_timeout (
Optional
[float
]) – Timeout in seconds for the call. - cancel_mode (
Optional
[NewType()
(CancelMode
,str
)]) – Cancel mode to use when cancelling the call. Seeaiowamp.Call.cancel
. - disclose_me (
Optional
[bool
]) – Whether to disclose the client to the callee. - resource_key (
Optional
[str
]) – Resource key for sharded registrations. - options (
Optional
[Dict
[str
,ForwardRef
]]) – Additional options to pass. - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) –
Return type: CallABC
Returns: The call instance to interact with the call.
- procedure (
-
-
class
aiowamp.
ClientABC
[source]¶ WAMP Client.
Implements the publisher, subscriber, caller, and callee roles.
-
call
(procedure, *args, kwargs=None, receive_progress=None, call_timeout=None, cancel_mode=None, disclose_me=None, resource_key=None, options=None)[source]¶ Call a remote procedure.
Parameters: - procedure (
str
) – Procedure uri to call. - *args – Arguments to pass to the call.
- kwargs (
Optional
[Dict
[str
,ForwardRef
]]) – Keyword arguments to pass to the call. - receive_progress (
Optional
[bool
]) – Whether the callee may send progress results. - call_timeout (
Optional
[float
]) – Timeout in seconds for the call. - cancel_mode (
Optional
[NewType()
(CancelMode
,str
)]) – Cancel mode to use when cancelling the call. Seeaiowamp.Call.cancel
. - disclose_me (
Optional
[bool
]) – Whether to disclose the client to the callee. - resource_key (
Optional
[str
]) – Resource key for sharded registrations. - options (
Optional
[Dict
[str
,ForwardRef
]]) – Additional options to pass. - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) –
Return type: CallABC
Returns: The call instance to interact with the call.
- procedure (
-
close
(details=None, *, reason=None)[source]¶ Close the client and the underlying session.
Parameters: Return type: None
-
publish
(topic, *args, kwargs=None, acknowledge=None, blackwhitelist=None, exclude_me=None, disclose_me=None, resource_key=None, options=None)[source]¶ Publish an event to a topic.
Parameters: - topic (
str
) – Topic uri to publish to. - *args – Arguments for the event.
- kwargs (
Optional
[Dict
[str
,ForwardRef
]]) – Keyword arguments for the event. - acknowledge (
Optional
[bool
]) – Whether to wait for the router to acknowledge the event. - blackwhitelist (
Optional
[BlackWhiteList
]) – Black- and whitelisting subscribers. - exclude_me (
Optional
[bool
]) – Whether the client should receive this event. - disclose_me (
Optional
[bool
]) – Whether the client’s identity should be disclosed to subscribers. - resource_key (
Optional
[str
]) – Resource key for sharded subscriptions. - options (
Optional
[Dict
[str
,ForwardRef
]]) – Additional options. - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) –
Return type: None
- topic (
-
register
(procedure, handler, *, disclose_caller=None, match_policy=None, invocation_policy=None, options=None)[source]¶ Register a procedure.
Parameters: - procedure (
str
) – Procedure URI to register. - handler (
Callable
[[ForwardRef
],Union
[Awaitable
[ForwardRef
],AsyncGenerator
[ForwardRef
,None
]]]) – Procedure to call. - disclose_caller (
Optional
[bool
]) – Whether callers’ identities should be disclosed. - match_policy (
Optional
[NewType()
(MatchPolicy
,str
)]) – Match policy for the procedure uri. Can also be specified by passing anaiowamp.URI
with a match policy to the procedure. - invocation_policy (
Optional
[NewType()
(InvocationPolicy
,str
)]) – Invocation policy. - options (
Optional
[Dict
[str
,ForwardRef
]]) – Additional options to pass.
Return type: Returns: The registration id of the registered procedure. Can be used to unregister the procedure.
- procedure (
-
subscribe
(topic, callback, *, match_policy=None, node_key=None, options=None)[source]¶ Subscribe to a topic.
Parameters: - topic (
str
) – Topic uri to subscribe to. - callback (
Callable
[[ForwardRef
],Union
[Any
,Awaitable
[Any
]]]) – Callable to call for each event. - match_policy (
Optional
[NewType()
(MatchPolicy
,str
)]) – Match policy for the uri. Can also be specified by passing anaiowamp.URI
with a match policy. - node_key (
Optional
[str
]) – Node key for sharded subscriptions. - options (
Optional
[Dict
[str
,ForwardRef
]]) – Additional options to pass.
Return type: - topic (
-
unregister
(procedure, registration_id=None)[source]¶ Unregister a procedure.
Parameters: Raises: KeyError
– If no registration for the procedure exists.Return type: None
-
-
class
aiowamp.
CommonTransportConfig
(url, serializer=None, ssl_context=None)[source]¶ Transport configuration used by transport factories.
Parameters: - url (urlparse.ParseResult) –
- serializer (Optional['aiowamp.SerializerABC']) –
- ssl_context (Optional[ssl.SSLContext]) –
-
url
= None¶ URL to connect to.
-
ssl_context
= None¶ SSL options.
If
None
, TLS will still be used if theurl
specifies a secure scheme (ex: “wss”).
-
__weakref__
¶ list of weak references to the object (if defined)
-
exception
aiowamp.
ErrorResponse
(message)[source]¶ Parameters: message ( Error
) –-
__init__
(message)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Parameters: message ( Error
) –
-
message
¶ Error message.
-
-
class
aiowamp.
IDGenerator
[source]¶ Sequential ID generator.
Generates sequential ids starting from 1 up to 2^53 (inclusive) before restarting.
Create a new id generator.
The first generated id will be 1.
-
class
aiowamp.
IDGeneratorABC
[source]¶ Abstract WAMP ID generator type.
Should be used like an iterator by passing it to
next
. Note that the generator should never raiseStopIteration
.
-
exception
aiowamp.
Interrupt
(options)[source]¶ Parameters: options ( Dict
[str
,ForwardRef
]) –-
__init__
(options)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Parameters: options ( Dict
[str
,ForwardRef
]) –Return type: None
-
options
¶ Options sent with the interrupt.
-
cancel_mode
¶ Cancel mode sent with the interrupt.
-
-
class
aiowamp.
Invocation
(session, client, msg, *, procedure)[source]¶ Create a new invocation instance.
Normally you should not create these yourself, they don’t actively listen for incoming messages. Instead, they rely on the
aiowamp.ClientABC
to receive and pass them.Parameters: - session (
SessionABC
) – WAMP Session to send messages in. - msg (
Invocation
) – Invocation message that spawned the invocation. - procedure (
URI
) – Registered procedure URI. - client (~ClientT) –
-
__init__
(session, client, msg, *, procedure)[source]¶ Create a new invocation instance.
Normally you should not create these yourself, they don’t actively listen for incoming messages. Instead, they rely on the
aiowamp.ClientABC
to receive and pass them.Parameters: - session (
SessionABC
) – WAMP Session to send messages in. - msg (
Invocation
) – Invocation message that spawned the invocation. - procedure (
URI
) – Registered procedure URI. - client (~ClientT) –
Return type: None
- session (
-
session
¶ Session used to send messages.
-
__getitem__
(key)[source]¶ Get a value from the arguments or keyword arguments.
Parameters: key ( Union
[int
,str
]) – Key to get value for. If the key is a string, the value is looked up in the keyword arguments. Integers are treated as indices to the arguments.Return type: Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]Returns: Value for the given key. Raises: LookupError
– If the key doesn’t exist.
-
client
¶ Underlying client that received the invocation.
Return type: ~ClientT
-
registered_procedure
¶ URI that was used to register the procedure.
See
procedure
for the uri that was called.Return type: URI
-
args
¶ Call arguments.
Return type: Tuple
[Union
[int
,str
,bool
,ForwardRef
,ForwardRef
], …]
-
kwargs
¶ Call keyword arguments.
Return type: Dict
[str
,ForwardRef
]
-
details
¶ Additional call details.
Return type: Dict
[str
,ForwardRef
]
-
timeout
¶ Timeout in seconds.
0
if no timeout was provided which means the call doesn’t time out.Return type: float
-
timeout_at
¶ Time at which the invocation will be cancelled.
None
if the call doesn’t time out.Trying to send a message (result, progress, error) after the call is cancelled will raise an exception. Use
done
to check whether the invocation can send messages.Return type: Optional
[datetime
]
-
interrupt
¶ Interrupt message sent by the caller.
None
if the message hasn’t been interrupted.Return type: Optional
[Interrupt
]
-
send_error
(error, *args, kwargs=None, details=None)[source]¶ Send an error.
This completes the invocation.
Parameters: - error (
str
) – URI of the error. - *args – Arguments for the result.
- kwargs (
Optional
[Dict
[str
,ForwardRef
]]) – Keyword arguments for the result. - details (
Optional
[Dict
[str
,ForwardRef
]]) – Additional details to send. - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) –
Return type: None
- error (
-
send_progress
(*args, kwargs=None, options=None)[source]¶ Send a progress result.
Use
may_send_progress
to check whether the caller is willing to receive progress results.Parameters: - *args – Arguments for the result.
- kwargs (
Optional
[Dict
[str
,ForwardRef
]]) – Keyword arguments for the result. - options (
Optional
[Dict
[str
,ForwardRef
]]) – Additional options to send. - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) –
Return type: None
-
send_result
(*args, kwargs=None, options=None)[source]¶ Send the final result.
This completes the invocation.
Parameters: - *args – Arguments for the result.
- kwargs (
Optional
[Dict
[str
,ForwardRef
]]) – Keyword arguments for the result. - options (
Optional
[Dict
[str
,ForwardRef
]]) – Additional options to send. - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) –
Return type: None
- session (
-
class
aiowamp.
InvocationABC
[source]¶ Invocation context passed to a procedure.
-
client
¶ Underlying client that received the invocation.
Return type: ~ClientT
-
registered_procedure
¶ URI that was used to register the procedure.
See
procedure
for the uri that was called.Return type: URI
-
procedure
¶ Concrete procedure that caused the invocation.
This will be the same as
registered_procedure
unless the procedure was registered with a pattern-based matching policy.Return type: URI
-
args
¶ Call arguments.
Return type: Tuple
[Union
[int
,str
,bool
,ForwardRef
,ForwardRef
], …]
-
kwargs
¶ Call keyword arguments.
Return type: Dict
[str
,ForwardRef
]
-
details
¶ Additional call details.
Return type: Dict
[str
,ForwardRef
]
-
may_send_progress
¶ Whether or not the caller is willing to receive progressive results.
Return type: bool
-
caller_id
¶ Get the caller’s id.
You can specify the “disclose_caller” option when registering a procedure to force disclosure.
Return type: Optional
[int
]Returns: WAMP id of the caller, or None
if not specified.
-
trust_level
¶ Get the router assigned trust level.
The trust level 0 means lowest trust, and higher integers represent (application-defined) higher levels of trust.
Return type: Optional
[int
]Returns: The trust level, or None
if not specified.
-
timeout
¶ Timeout in seconds.
0
if no timeout was provided which means the call doesn’t time out.Return type: float
-
timeout_at
¶ Time at which the invocation will be cancelled.
None
if the call doesn’t time out.Trying to send a message (result, progress, error) after the call is cancelled will raise an exception. Use
done
to check whether the invocation can send messages.Return type: Optional
[datetime
]
-
interrupt
¶ Interrupt message sent by the caller.
None
if the message hasn’t been interrupted.Return type: Optional
[Interrupt
]
-
send_error
(error, *args, kwargs=None, details=None)[source]¶ Send an error.
This completes the invocation.
Parameters: - error (
str
) – URI of the error. - *args – Arguments for the result.
- kwargs (
Optional
[Dict
[str
,ForwardRef
]]) – Keyword arguments for the result. - details (
Optional
[Dict
[str
,ForwardRef
]]) – Additional details to send. - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) –
Return type: None
- error (
-
send_progress
(*args, kwargs=None, options=None)[source]¶ Send a progress result.
Use
may_send_progress
to check whether the caller is willing to receive progress results.Parameters: - *args – Arguments for the result.
- kwargs (
Optional
[Dict
[str
,ForwardRef
]]) – Keyword arguments for the result. - options (
Optional
[Dict
[str
,ForwardRef
]]) – Additional options to send. - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) –
Return type: None
-
send_result
(*args, kwargs=None, options=None)[source]¶ Send the final result.
This completes the invocation.
Parameters: - *args – Arguments for the result.
- kwargs (
Optional
[Dict
[str
,ForwardRef
]]) – Keyword arguments for the result. - options (
Optional
[Dict
[str
,ForwardRef
]]) – Additional options to send. - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) –
Return type: None
-
-
exception
aiowamp.
InvocationError
(uri, *args, kwargs=None, details=None)[source]¶ Parameters: - uri (
str
) – - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) – - kwargs (
Optional
[Dict
[str
,ForwardRef
]]) – - details (
Optional
[Dict
[str
,ForwardRef
]]) –
-
__init__
(uri, *args, kwargs=None, details=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Parameters: - uri (
str
) – - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) – - kwargs (
Optional
[Dict
[str
,ForwardRef
]]) – - details (
Optional
[Dict
[str
,ForwardRef
]]) –
Return type: None
- uri (
- uri (
-
class
aiowamp.
InvocationProgress
(*args, **kwargs)[source]¶ Helper class for procedures.
Instances of this class can be yielded by procedures to indicate that it it’s intended to be sent as a progress.
Usually, because there’s no way to tell whether an async generator has yielded for the last time, aiowamp waits for the next yield before sending a progress result (i.e. it always lags behind one message). When returning an instance of this class however, aiowamp will send it immediately.
It is possible to abuse this by returning an instance of this class for the final yield. This is not supported by the WAMP protocol and currently results in aiowamp sending an empty final result.
Parameters: - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) – - kwargs (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) –
- args (
-
class
aiowamp.
InvocationResult
(*args, **kwargs)[source]¶ Helper class for procedures.
Use this to return/yield a result from a
aiowamp.InvocationHandler
containing keyword arguments.Parameters: - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) – - kwargs (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) –
-
__init__
(*args, **kwargs)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Parameters: - args (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) – - kwargs (
Union
[int
,str
,bool
,ForwardRef
,ForwardRef
]) –
Return type: None
- args (
-
args
¶ Arguments.
-
kwargs
¶ Keyword arguments.
-
details
¶ Details.
- args (
-
class
aiowamp.
JSONSerializer
(*, decoder=None, encoder=None)[source]¶ Serializer for the JSON format.
Provides a custom
json.JSONDecoder
andjson.JSONEncoder
which handle the special WAMP string format for binary data.Parameters: -
decoder
¶ JSON decoder used to decode incoming messages.
-
encoder
¶ JSON encoder used to encode outgoing messages.
-
serialize
(msg)[source]¶ Serialise a message.
Parameters: msg ( MessageABC
) – Message to serialise.Return type: bytes
Returns: bytes
representation of the message.Raises: Exception
– If the message couldn’t be serialised.
-
deserialize
(data)[source]¶ Deserialise the
bytes
representation of a message.Parameters: Return type: MessageABC
Returns: Deserialised message.
Raises: aiowamp.InvalidMessage
– If the deserialised data isn’t a message.Exception
– If the message couldn’t be deserialised.
-
-
class
aiowamp.
MessageABC
[source]¶ Base class for WAMP messages.
-
message_type
= None¶ Type code of the message.
-
to_message_list
()[source]¶ Convert the message to a list
Return type: List
[ForwardRef
]Returns: List containing the message including the message type.
-
classmethod
from_message_list
(msg_list)[source]¶ Build the message from msg_list.
Parameters: - msg_list (
List
[ForwardRef
]) – Message list without the message type. - cls (
Type
[~T]) –
Return type: ~T
Returns: Instance of the message type.
- msg_list (
-
-
class
aiowamp.
MessagePackSerializer
[source]¶ -
serialize
(msg)[source]¶ Serialise a message.
Parameters: msg ( MessageABC
) – Message to serialise.Return type: bytes
Returns: bytes
representation of the message.Raises: Exception
– If the message couldn’t be serialised.
-
deserialize
(data)[source]¶ Deserialise the
bytes
representation of a message.Parameters: Return type: MessageABC
Returns: Deserialised message.
Raises: aiowamp.InvalidMessage
– If the deserialised data isn’t a message.Exception
– If the message couldn’t be deserialised.
-
-
class
aiowamp.
RawSocketTransport
(reader, writer, serializer, *, recv_limit, send_limit)[source]¶ WAMP transport over raw sockets.
Notes
The
start
method needs to be called beforerecv
can read any messages. This is done as part of theperform_client_handshake
procedure.Parameters: - reader (
StreamReader
) – - writer (
StreamWriter
) – - serializer (
SerializerABC
) – - recv_limit (
int
) – - send_limit (
int
) – - reader – Reader to read from.
- writer – Writer to write to.
- serializer – Serializer to use.
- recv_limit – Max amount of bytes willing to receive.
- send_limit – Max amount of bytes remote is willing to receive.
See also
The
connect_raw_socket
method for opening a connection.-
__init__
(reader, writer, serializer, *, recv_limit, send_limit)[source]¶ Parameters: See also
The
connect_raw_socket
method for opening a connection.Return type: None
-
reader
¶ Reader for the underlying stream.
-
writer
¶ Writer for the underlying transport.
-
serializer
¶ Serializer used to serialise messages.
- reader (
-
class
aiowamp.
SerializerABC
[source]¶ Serializer for messages.
Normally an
aiowamp.TransportABC
keeps a serializer which it uses.Deliberately doesn’t adhere to Python’s dump / load interface because the objects in question are always
aiowamp.MessageABC
and the serialized format is alwaysbytes
.-
serialize
(msg)[source]¶ Serialise a message.
Parameters: msg ( MessageABC
) – Message to serialise.Return type: bytes
Returns: bytes
representation of the message.Raises: Exception
– If the message couldn’t be serialised.
-
deserialize
(data)[source]¶ Deserialise the
bytes
representation of a message.Parameters: Return type: MessageABC
Returns: Deserialised message.
Raises: aiowamp.InvalidMessage
– If the deserialised data isn’t a message.Exception
– If the message couldn’t be deserialised.
-
-
class
aiowamp.
Session
(transport, session_id, realm, details, *, control_transport=True)[source]¶ Parameters: -
__init__
(transport, session_id, realm, details, *, control_transport=True)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Parameters: Return type: None
-
transport
¶ Transport used by the session.
-
control_transport
¶ Whether the session controls the underlying transport.
If this is
True
, the session will close the transport when it
-
-
class
aiowamp.
SessionABC
[source]¶ Abstract session type.
A Session is a transient conversation between two Peers attached to a Realm and running over a Transport.
-
class
aiowamp.
SubscriptionEvent
(client, msg, *, topic)[source]¶ Create a new SubscriptionEven instance.
There shouldn’t be a need to create these yourself, unless you’re creating your own
aiowamp.ClientABC
. Unlikeaiowamp.Invocation
it doesn’t require to be managed though.Parameters: - client (~ClientT) – Client used to unsubscribe.
- msg (
Event
) – Event message. - topic (
URI
) – Registered topic URI.
-
__init__
(client, msg, *, topic)[source]¶ Create a new SubscriptionEven instance.
There shouldn’t be a need to create these yourself, unless you’re creating your own
aiowamp.ClientABC
. Unlikeaiowamp.Invocation
it doesn’t require to be managed though.Parameters: - client (~ClientT) – Client used to unsubscribe.
- msg (
Event
) – Event message. - topic (
URI
) – Registered topic URI.
Return type: None
-
client
¶ Underlying client that received the event.
Return type: ~ClientT
-
subscribed_topic
¶ URI of the subscription.
This is the uri that was passed to the subscribe method.
See
topic
for the uri that the event was published to.Return type: URI
-
args
¶ Event arguments.
Return type: Tuple
[Union
[int
,str
,bool
,ForwardRef
,ForwardRef
], …]
-
kwargs
¶ Event keyword arguments.
Return type: Dict
[str
,ForwardRef
]
-
details
¶ Additional event details.
Return type: Dict
[str
,ForwardRef
]
-
class
aiowamp.
SubscriptionEventABC
[source]¶ Subscription event.
-
client
¶ Underlying client that received the event.
Return type: ~ClientT
-
subscribed_topic
¶ URI of the subscription.
This is the uri that was passed to the subscribe method.
See
topic
for the uri that the event was published to.Return type: URI
-
topic
¶ Concrete topic that caused the event.
This will be the same as
subscribed_topic
unless the handler subscribed with a pattern-based matching policy.Return type: URI
-
args
¶ Event arguments.
Return type: Tuple
[Union
[int
,str
,bool
,ForwardRef
,ForwardRef
], …]
-
kwargs
¶ Event keyword arguments.
Return type: Dict
[str
,ForwardRef
]
-
details
¶ Additional event details.
Return type: Dict
[str
,ForwardRef
]
-
publisher_id
¶ Get the publisher’s id.
Return type: Optional
[int
]Returns: WAMP id of the caller, or None
if not disclosed.
-
-
class
aiowamp.
TicketAuth
(ticket)[source]¶ Auth method for ticket-based authentication.
With Ticket-based authentication, the client needs to present the server an authentication “ticket” - some magic value to authenticate itself to the server.
This “ticket” could be a long-lived, pre-agreed secret (e.g. a user password) or a short-lived authentication token (like a Kerberos token). WAMP does not care or interpret the ticket presented by the client.
Caution: This scheme is extremely simple and flexible, but the resulting security may be limited. E.g., the ticket value will be sent over the wire. If the transport WAMP is running over is not encrypted, a man-in-the-middle can sniff and possibly hijack the ticket. If the ticket value is reused, that might enable replay attacks.Parameters: ticket ( str
) –-
__init__
(ticket)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Parameters: ticket ( str
) –Return type: None
-
authenticate
(challenge)[source]¶ Generate an authenticate message for the challenge.
Parameters: challenge ( Challenge
) – Challenge message to respond to.Return type: Authenticate
Returns: Either an authenticate message to send to the router or an abort message to indicate that the attempt should be aborted. Raises: Exception
– When something goes wrong during authentication. Should be interpreted the same as an abort message.
-
-
class
aiowamp.
TransportABC
[source]¶ Abstract transport type.
A Transport connects two WAMP Peers and provides a channel over which WAMP messages for a WAMP Session can flow in both directions.
WAMP can run over any Transport which is message-based, bidirectional, reliable and ordered.
-
class
aiowamp.
URI
[source]¶ WAMP URI.
A
URI
is a subclass ofstr
and can be used wherever a string would be expected. Apart from object identity (id
) URIs are also completely equal to their string equivalent (ex: “hash(aiowamp.URI(‘a’)) == hash(‘a’)).The benefit of URIs (apart from the semantics) is that they can carry a
MatchPolicy
with them. All functions that accept a “match_policy” keyword argument will also check for thematch_policy
(Note that the keyword argument will always be used if specified).Create a new uri.
Parameters: - uri – URI to set the value to.
- match_policy – Match policy to use for the URI.
Defaults to
None
.
Returns: New uri instance.
-
match_policy
¶ Match policy passed to the instance.
-
static
__new__
(cls, uri, *, match_policy=None)[source]¶ Create a new uri.
Parameters: Return type: ~T
Returns: New uri instance.
-
classmethod
cast
(uri)[source]¶ Cast the string to a uri.
Parameters: Return type: ~T
Returns: If the uri is already an instance of URI, it is returned directly. Otherwise a new URI is created.
-
classmethod
policy_match
(policy, uri, other)[source]¶ Check if a uri matches another based on the policy.
Parameters: Return type: Returns: Whether the uri matches the pattern “other”.
Raises: ValueError
– If an invalid policy was specified.
-
static
prefix_match
(uri, prefix)[source]¶ Check whether the URI matches the prefix.
Parameters: Return type: Returns: Whether the URI has the given prefix.
-
exception
aiowamp.
UnexpectedMessageError
(received, expected)[source]¶ Exception raised when an unexpected message type is received.
Parameters: - received (aiowamp.MessageABC) –
- expected (Type['aiowamp.MessageABC']) –
-
received
¶ Message that was received.
-
expected
¶ Message type that was expected.
-
class
aiowamp.
WebSocketTransport
(ws_client, serializer, *, payload_text)[source]¶ WAMP Transport over web socket.
Parameters: -
ws_client
¶ Underlying web socket client.
-
serializer
¶ Serializer used for the transport.
-
-
aiowamp.
build_message_from_list
(msg_list)[source]¶ Create a message from msg_list.
Uses the registered message type.
Parameters: msg_list ( List
[ForwardRef
]) – Message list containing the message type as the first element.Return type: MessageABC
Returns: Built message. Raises: aiowamp.InvalidMessage
– If the message is invalid.
-
aiowamp.
connect
(url, *, realm, serializer=None, keyring=None)[source]¶ Connect to a router, join a realm, and create a client.
Parameters: Return type: Client
Returns: Client wrapping the established session.
Raises: Exception
– If the connection fails.AbortError
– If the joining was aborted.AuthError
– If the authentication failed.
-
aiowamp.
connect_transport
(config)[source]¶ Connect a transport based on the config.
Parameters: config (
CommonTransportConfig
) – Config to create the transport with.Return type: TransportABC
Returns: A connected transport.
Raises: Notes
Uses
aiowamp.get_transport_factory
to get the transport factory from which the transport is created.
-
aiowamp.
get_message_cls
(msg_type)[source]¶ Returns the message type registered for msg_type.
Parameters: msg_type ( int
) – Message type to look for.Return type: Type
[ForwardRef
]Returns: Message type registered for msg_type. Raises: KeyError
– If no message type is registered for msg_type.
-
aiowamp.
get_transport_factory
(scheme)[source]¶ Get the registered transport factory for the scheme.
Parameters: scheme ( str
) – URL scheme to get factory for.Return type: Callable
[[CommonTransportConfig
],Awaitable
[TransportABC
]]Returns: A transport factory callable. Raises: KeyError
– If no transport is registered for the given scheme.
-
aiowamp.
is_message_type
(msg, msg_type)[source]¶ Checks whether msg is of type msg_type.
This should be preferred over
isinstance
checks as it supports duck typing. If, however, the built-in message class is overwritten with a custom one and you depend on a specific feature of said class thenisinstance
should be used.Parameters: - msg (
MessageABC
) – Message to check. - msg_type (
Type
[ForwardRef
]) – Message type to check against. IMPORTANT: The function doesn’t actually cast to the type, it is assumed that if two message types share the same type code, they are interchangeable.
Return type: Returns: Whether msg and msg_type have the same
aiowamp.MessageABC.message_type
.- msg (
-
aiowamp.
join_realm
(transport, realm, *, keyring=None, roles=None, details=None)[source]¶ Join a realm on a router.
Parameters: - transport (
TransportABC
) – Transport to run the session over. - realm (
str
) – Realm to join. - keyring (
Optional
[AuthKeyringABC
]) – Authentication keyring to use for authentication. - roles (
Optional
[Dict
[str
,ForwardRef
]]) – Roles to announce with. - details (
Optional
[Dict
[str
,ForwardRef
]]) – Additional details to send with the hello message.
Return type: Session
Returns: Session running over the transport connected to the realm.
Raises: AbortError
– If the joining was aborted.AuthError
– If the authentication failed.
- transport (
-
aiowamp.
message_as_type
(msg, msg_type)[source]¶ Cast msg if it is of type msg_type.
Uses
aiowamp.is_message_type
to check if msg is of type msg_type.Parameters: - msg (
MessageABC
) – Message to cast. - msg_type (
Type
[~MsgT]) – Message type to cast to.
Return type: Optional
[~MsgT]Returns: None
, if msg is not of type msg_type, otherwise it returns msg.Examples
This function can be used as a type guard:
>>> import aiowamp >>> msg: aiowamp.MessageABC = aiowamp.msg.Hello(aiowamp.URI(""), {}) >>> # type of hello_msg is inferred as Optional[aiowamp.msg.Hello] >>> hello_msg = message_as_type(msg, aiowamp.msg.Hello) >>> hello_msg is msg True
- msg (
-
aiowamp.
register_message_cls
(*messages, overwrite=False)[source]¶ Register the messages.
Parameters: - *messages – Message types to register.
- overwrite (
bool
) – If existing types should be overwritten. Defaults toFalse
which makes overwriting an existing message type an error. - messages (
Type
[ForwardRef
]) –
Raises: ValueError
– If the message type for a message is already registered by another type and overwrite isFalse
.Return type: None
-
aiowamp.
register_transport_factory
(*schemes, overwrite=False)[source]¶ Decorator for registering transport factories.
Registered transport factories can be retrieved by
aiowamp.get_transport_factory
.Parameters: Raises: ValueError
– If a scheme is already registered to another factory and overwrite isFalse
.
-
aiowamp.
set_invocation_error
(exc, err)[source]¶ Attach an invocation error to an exception.
This makes it possible to raise a seemingly normal python
Exception
while preserving the additional information for WAMP.The attached error can then be retrieved by
exception_to_invocation_error
.If the exception is an invocation error, it is overwritten with the new error.
Parameters: - exc (
Exception
) – Exception to attach the invocation error to. - err (
InvocationError
) – Invocation error to attach.
Return type: None
- exc (
Templates¶
-
aiowamp.templ.
create_invocation_entry_point
(fn)[source]¶ Create an invocation handler for the given callable.
Parameters: fn ( Callable
) – Function to generate invocation handler for.Return type: Callable
[[InvocationABC
],Union
[Awaitable
[Union
[ForwardRef
,Tuple
[ForwardRef
, …],None
,ForwardRef
]],AsyncGenerator
[Union
[ForwardRef
,Tuple
[ForwardRef
, …],None
,ForwardRef
],None
]]]Returns: A wrapper which acts like an entry point for the given function. It gets all arguments requested by the function’s signature from the invocation and calls it.
-
aiowamp.templ.
create_subscription_entry_point
(fn)[source]¶ Create subscription handler for the given callable.
Parameters: fn ( Callable
) – Function to generate subscription handler for.Return type: Callable
[[SubscriptionEventABC
],Union
[Any
,Awaitable
[Any
]]]Returns: A wrapper which acts like an entry point for the given function. It gets all arguments requested by the function’s signature from the subscription event and calls it.