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)

Stream events for one, multiple, or all device(s) in a project.

Implements a basic retry-routine. If connection is lost, the stream will attempt to reconnect with an exponential backoff. Events that are published during reconnection are not accounted for.

If you want to forward your data in a server-to-server integration, consider using Data Connectors for a simpler and more reliable service with an added at-least-once guarantee.

  • 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 (Any) – Arbitrary keyword arguments. See the Configuration page.


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

Return type:



>>> # Sream real-time events from all devices in a project.
>>> for event in dt.Stream.event_stream('<PROJECT_ID>'):
...     print(event)
>>> # Sream real-time temperature- and touch events
>>> # only from temperature devices that have set
>>> # the labels `room-number=99` or `group=red`.
>>> stream = dt.Stream.event_stream(
...     project_id='<PROJECT_ID>',
...     label_filters={
...         'room-number': '99',
...         'group': 'red',
...     },
...     device_types=[
...         dt.Device.TEMPERATURE,
...     ],
...     event_types=[
...     ],
... )
>>> for event in stream:
...     print(event)