ftrack_api.event.hub

class ftrack_api.event.hub.SocketIoSession(id, heartbeatTimeout, supportedTransports)
__init__

Initialize self. See help(type(self)) for accurate signature.

count()

Return number of occurrences of value.

heartbeatTimeout

Alias for field number 1

id

Alias for field number 0

index()

Return first index of value.

Raises ValueError if the value is not present.

supportedTransports

Alias for field number 2

class ftrack_api.event.hub.ServerDetails(scheme, hostname, port)
__init__

Initialize self. See help(type(self)) for accurate signature.

count()

Return number of occurrences of value.

hostname

Alias for field number 1

index()

Return first index of value.

Raises ValueError if the value is not present.

port

Alias for field number 2

scheme

Alias for field number 0

class ftrack_api.event.hub.EventHub(server_url, api_user, api_key)[source]

Manage routing of events.

__init__(server_url, api_user, api_key)[source]

Initialise hub, connecting to ftrack server_url.

api_user is the user to authenticate as and api_key is the API key to authenticate with.

get_server_url()[source]

Return URL to server.

get_network_location()[source]

Return network location part of url (hostname with optional port).

secure

Return whether secure connection used.

connect()[source]

Initialise connection to server.

Raise ftrack_api.exception.EventHubConnectionError if already connected or connection fails.

connected

Return if connected.

disconnect(unsubscribe=True)[source]

Disconnect from server.

Raise ftrack_api.exception.EventHubConnectionError if not currently connected.

If unsubscribe is True then unsubscribe all current subscribers automatically before disconnecting.

reconnect(attempts=10, delay=5)[source]

Reconnect to server.

Make attempts number of attempts with delay in seconds between each attempt.

Note

All current subscribers will be automatically resubscribed after successful reconnection.

Raise ftrack_api.exception.EventHubConnectionError if fail to reconnect.

wait(duration=None)[source]

Wait for events and handle as they arrive.

If duration is specified, then only process events until duration is reached. duration is in seconds though float values can be used for smaller values.

get_subscriber_by_identifier(identifier)[source]

Return subscriber with matching identifier.

Return None if no subscriber with identifier found.

subscribe(subscription, callback, subscriber=None, priority=100)[source]

Register callback for subscription.

A subscription is a string that can specify in detail which events the callback should receive. The filtering is applied against each event object. Nested references are supported using ‘.’ separators. For example, ‘topic=foo and data.eventType=Shot’ would match the following event:

<Event {'topic': 'foo', 'data': {'eventType': 'Shot'}}>

The callback should accept an instance of ftrack_api.event.base.Event as its sole argument.

Callbacks are called in order of priority. The lower the priority number the sooner it will be called, with 0 being the first. The default priority is 100. Note that priority only applies against other callbacks registered with this hub and not as a global priority.

An earlier callback can prevent processing of subsequent callbacks by calling Event.stop() on the passed event before returning.

Warning

Handlers block processing of other received events. For long running callbacks it is advisable to delegate the main work to another process or thread.

A callback can be attached to subscriber information that details the subscriber context. A subscriber context will be generated automatically if not supplied.

Note

The subscription will be stored locally, but until the server receives notification of the subscription it is possible the callback will not be called.

Return subscriber identifier.

Raise ftrack_api.exception.NotUniqueError if a subscriber with the same identifier already exists.

unsubscribe(subscriber_identifier)[source]

Unsubscribe subscriber with subscriber_identifier.

Note

If the server is not reachable then it won’t be notified of the unsubscription. However, the subscriber will be removed locally regardless.

publish(event, synchronous=False, on_reply=None, on_error='raise')[source]

Publish event.

If synchronous is specified as True then this method will wait and return a list of results from any called callbacks.

Note

Currently, if synchronous is True then only locally registered callbacks will be called and no event will be sent to the server. This may change in future.

on_reply is an optional callable to call with any reply event that is received in response to the published event.

Note

Will not be called when synchronous is True.

If on_error is set to ‘ignore’ then errors raised during publish of event will be caught by this method and ignored.

publish_reply(source_event, data, source=None)[source]

Publish a reply event to source_event with supplied data.

If source is specified it will be used for the source value of the sent event.

subscription(subscription, callback, subscriber=None, priority=100)[source]

Return context manager with callback subscribed to subscription.

The subscribed callback will be automatically unsubscribed on exit of the context manager.