The Stream resource can be used to stream device Events in real-time. This can be achieved by using the API Methods included in the class.

Each new event in the stream is represented by an instance of the Event class.

API Methods

disruptive.Stream.event_stream(project_id, device_ids=None, label_filters=None, device_types=None, event_types=None, **kwargs)

Streams events for one, several, or all devices in a project.

Implements a basic retry-routine. If connection is lost, the stream will attempt to reconnect with an exponential backoff. Potential lost events while reconnecting are, however, not acocunted for.

  • project_id (str) – Unique ID of the target project.

  • device_ids (list[str], optional) – Only includes events from the specified device(s).

  • label_filters (dict[str, Optional[str]], optional) – Filter devices by their labels. Takes the form {"key": "value"}, or {"key": None} to allow any label value.

  • device_types (list[str], optional) – Only includes events from devices with specified type(s).

  • event_types (list[str], optional) – Only includes events of the specified type(s).

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.


stream – A python Generator type that yields each new event in the stream.

Return type:



>>> # Stream real-time events from all devices in a project.
>>> for event in dt.Stream.event_stream('<PROJECT_ID>'):
...     print(event)
>>> # Stream real-time events from one device in a project.
>>> for event in dt.Stream.event_stream(project_id='<PROJECT_ID>',
...                                     device_ids=['<DEVICE_ID>'],
...                                     ):
...     print(event)
>>> # Stream real-time touch events from a select list of
>>> # humidity- and touch sensors, but only those with
>>> # a 'v1' label in room number 99.
>>> for e in dt.Stream.event_stream(project_id='<PROJECT_ID>',
...                                 device_ids=[
...                                     '<DEVICE_ID_1>',
...                                     '<DEVICE_ID_2>',
...                                     '<DEVICE_ID_3>',
...                                 ]
...                                 event_types=['touch'],
...                                 device_types=['humidity', 'touch'],
...                                 label_filters={
...                                     'v1': None,
...                                     'room-number': '99',
...                                 },
...                                 ):
...     print(