API Reference¶
Client¶
-
class
aiocometd.
Client
(url, connection_types=None, *, connection_timeout=10.0, ssl=None, max_pending_count=100, extensions=None, auth=None, json_dumps=<function dumps>, json_loads=<function loads>, loop=None)[source]¶ CometD client
Parameters: - url (
str
) – CometD service url - connection_types (
Union
[ConnectionType
,List
[ConnectionType
],None
]) – List of connection types in order of preference, or a single connection type name. IfNone
, [WEBSOCKET
,LONG_POLLING
] will be used as a default value. - connection_timeout (
Union
[int
,float
]) – The maximum amount of time to wait for the transport to re-establish a connection with the server when the connection fails. - ssl (
Union
[SSLContext
,bool
,Fingerprint
,None
]) – 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 (
Optional
[List
[Extension
]]) – List of protocol extension objects - auth (
Optional
[AuthExtension
]) – An auth extension - json_dumps (
Callable
[[Dict
[str
,Any
]],str
]) – Function for JSON serialization, the default isjson.dumps()
- json_loads (
Callable
[[str
],Dict
[str
,Any
]]) – Function for JSON deserialization, the default isjson.loads()
- loop (
Optional
[AbstractEventLoop
]) – Eventloop
used to schedule tasks. If loop isNone
thenasyncio.get_event_loop()
is used to get the default event loop.
-
coroutine
open
(self)[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.
Return type: None
-
coroutine
publish
(self, channel, data)[source]¶ Publish data to the given channel
Parameters: Return type: Returns: Publish response
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
(self, channel)[source]¶ Subscribe to channel
Parameters: channel (
str
) – Name of the channelRaises: - 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
Return type: None
- ClientInvalidOperation – If the client is
-
coroutine
unsubscribe
(self, channel)[source]¶ Unsubscribe from channel
Parameters: channel (
str
) – Name of the channelRaises: - 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
Return type: None
- ClientInvalidOperation – If the client is
-
coroutine
receive
(self)[source]¶ Wait for incoming messages from the server
Return type: Returns: Incoming message
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.
-
connection_type
¶ The current connection type in use if the client is open, otherwise
None
Return type: Optional
[ConnectionType
]
- url (
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
(self)[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
Return type: None
-
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
(message, response)[source]¶ CometD server side error
If the response contains an error field it gets parsed according to the specs
Parameters:
-
exception
aiocometd.exceptions.
TransportConnectionClosed
[source]¶ The connection unexpectedly closed