API Reference¶
Client¶
-
class
aiocometd.
Client
(url, connection_types=None, *, connection_timeout=10.0, ssl=None, max_pending_count=100, extensions=None, auth=None, loop=None)[source]¶ CometD client
Parameters: - url (str) – CometD service url
- connection_types (list[ConnectionType], ConnectionType or None) – List of connection types in order of preference, or a single connection type name. If
None
, [WEBSOCKET
,LONG_POLLING
] will be used as a default value. - connection_timeout (int, float or None) – The maximum amount of time to wait for the transport to re-establish a connection with the server when the connection fails.
- ssl – SSL validation mode. None for default SSL check (
ssl.create_default_context()
is used), False for skip SSL certificate validation, aiohttp.Fingerprint for fingerprint validation,ssl.SSLContext
for custom SSL certificate validation. - max_pending_count (int) – The maximum number of messages to prefetch from the server. If the number of prefetched messages reach this size then the connection will be suspended, until messages are consumed. If it is less than or equal to zero, the count is infinite.
- extensions (list[Extension] or None) – List of protocol extension objects
- auth (AuthExtension) – An auth extension
- loop – Event
loop
used to schedule tasks. If loop isNone
thenasyncio.get_event_loop()
is used to get the default event loop.
-
coroutine
open
()[source]¶ Establish a connection with the CometD server
This method works mostly the same way as the handshake method of CometD clients in the reference implementations.
Raises: - ClientError – If none of the connection types offered by the server are supported
- ClientInvalidOperation – If the client is already open, or in other words if it isn’t
closed
- TransportError – If a network or transport related error occurs
- ServerError – If the handshake or the first connect request gets rejected by the server.
-
coroutine
publish
(channel, data)[source]¶ Publish data to the given channel
Parameters: Returns: Publish response
Return type: Raises: - ClientInvalidOperation – If the client is
closed
- TransportError – If a network or transport related error occurs
- ServerError – If the publish request gets rejected by the server
- ClientInvalidOperation – If the client is
-
coroutine
subscribe
(channel)[source]¶ Subscribe to channel
Parameters: channel (str) – Name of the channel
Raises: - ClientInvalidOperation – If the client is
closed
- TransportError – If a network or transport related error occurs
- ServerError – If the subscribe request gets rejected by the server
- ClientInvalidOperation – If the client is
-
coroutine
unsubscribe
(channel)[source]¶ Unsubscribe from channel
Parameters: channel (str) – Name of the channel
Raises: - ClientInvalidOperation – If the client is
closed
- TransportError – If a network or transport related error occurs
- ServerError – If the unsubscribe request gets rejected by the server
- ClientInvalidOperation – If the client is
-
coroutine
receive
()[source]¶ Wait for incoming messages from the server
Returns: Incoming message
Return type: Raises: - ClientInvalidOperation – If the client is closed, and has no more pending incoming messages
- ServerError – If the client receives a confirmation message which is not
successful
- TransportTimeoutError – If the transport can’t re-establish connection with the server in
connection_timeout
time.
-
closed
¶ Marks whether the client is open or closed
-
subscriptions
¶ Set of subscribed channels
-
connection_type
¶ The current connection type in use if the client is open, otherwise
None
-
pending_count
¶ The number of pending incoming messages
Once
open
is called the client starts listening for messages from the server. The incoming messages are retrieved and stored in an internal queue until they get consumed by callingreceive
.
-
has_pending_messages
¶ Marks whether the client has any pending incoming messages
ConnectionType¶
Extensions¶
-
class
aiocometd.
Extension
[source]¶ Bases:
abc.ABC
Defines operations supported by extensions
-
class
aiocometd.
AuthExtension
[source]¶ Bases:
aiocometd.extensions.Extension
Extension with support for authentication
-
coroutine
authenticate
()[source]¶ Called after a failed authentication attempt
For authentication schemes where the credentials are static it doesn’t makes much sense to reimplement this function. However for schemes where the credentials can expire (like OAuth, JWT…) this method can be reimplemented to update those credentials
-
coroutine
Exceptions¶
Exception types
Exception hierarchy:
AiocometdException
ClientError
ClientInvalidOperation
TransportError
TransportInvalidOperation
TransportTimeoutError
TransportConnectionClosed
ServerError
-
exception
aiocometd.exceptions.
AiocometdException
[source]¶ Base exception type.
All exceptions of the package inherit from this class.
-
exception
aiocometd.exceptions.
ClientInvalidOperation
[source]¶ The requested operation can’t be executed on the current state of the client
-
exception
aiocometd.exceptions.
ServerError
[source]¶ CometD server side error
If the response contains an error field it gets parsed according to the specs
Parameters: -
message
¶ Error description
-
response
¶ Server response message
-
-
exception
aiocometd.exceptions.
TransportConnectionClosed
[source]¶ The connection unexpectedly closed