bluesky_tiled_plugins.streaming#
Module Contents#
Classes#
A selected Tiled update from a Bluesky data stream. |
|
Own recursive Tiled subscriptions for selected Bluesky event streams. |
Functions#
Subscribe to selected data keys in matching live Bluesky runs. |
Data#
API#
- bluesky_tiled_plugins.streaming.logger#
‘getLogger(…)’
- class bluesky_tiled_plugins.streaming.BlueskyStreamUpdate#
A selected Tiled update from a Bluesky data stream.
Parameters
run_uid : str Key of the direct
BlueskyRunparent. stream_name : str Name of the Bluesky data stream containing the updated node. data_keys : tuple of str Requested data keys represented by this update. A table update may contain several selected scalar keys; an array update contains one. update : LiveArrayData, LiveArrayRef, or LiveTableData Original Tiled live update. It is retained without decoding until :meth:datais called. sequence : int Native positive per-node Tiled streaming sequence number forupdate. Use it to correlate updates and detect duplicates or gaps for one node.- update: tiled.client.stream.LiveArrayData | tiled.client.stream.LiveArrayRef | tiled.client.stream.LiveTableData#
None
- data() Any#
Decode the original Tiled live update.
Returns
Any Tiled’s decoded array or table representation. When Tiled’s standard table decoder returns a pandas DataFrame, only :attr:
data_keysare included. Other Tiled-decoded table representations are returned unchanged.Notes
Decoding happens only when this method is called. Array references retain Tiled’s normal fetch behavior.
- class bluesky_tiled_plugins.streaming.BlueskyStreamSubscription(container: tiled.client.container.Container, streams: collections.abc.Mapping[str, tuple[str, ...] | None] | None, callback: collections.abc.Callable[[bluesky_tiled_plugins.streaming.BlueskyStreamUpdate], None], *, start: int | None, max_size: int, run_filter: collections.abc.Callable[[tiled.client.stream.LiveChildCreated], bool] | None)#
Own recursive Tiled subscriptions for selected Bluesky event streams.
- property closed: bool#
Whether teardown has begun.
Returns
bool
Trueafter :meth:disconnectmarks this manager closed. Tiled subscriptions may still be completing their blocking teardown.
- disconnect() None#
Disconnect every owned Tiled subscription.
Owned data-node subscriptions are disconnected before stream, run, and container subscriptions. This method is idempotent and blocks while Tiled closes sockets and waits for its subscription threads.
Raises
Exception The first error raised while disconnecting an owned Tiled subscription, after teardown is attempted for every owned subscription.
- bluesky_tiled_plugins.streaming.subscribe_to_streams(container: tiled.client.container.Container, callback: collections.abc.Callable[[bluesky_tiled_plugins.streaming.BlueskyStreamUpdate], None], *, streams: collections.abc.Mapping[str, str | collections.abc.Iterable[str] | None] | None, metadata_filter: collections.abc.Callable[[collections.abc.Mapping[str, Any]], bool] | None = None, required_specs: str | collections.abc.Iterable[str] | None = None, run_filter: collections.abc.Callable[[tiled.client.stream.LiveChildCreated], bool] | None = None, start: int | None = 0, max_size: int = 1000000) bluesky_tiled_plugins.streaming.BlueskyStreamSubscription#
Subscribe to selected data keys in matching live Bluesky runs.
Parameters
container : tiled.client.container.Container Direct parent of
BlueskyRunnodes created by :class:~bluesky_tiled_plugins.TiledWriter. callback : Callable[[BlueskyStreamUpdate], None] Function called for each selected native Tiled live update. streams : Mapping[str, str or iterable of str or None] or None Mapping from Bluesky event-stream name to its data-key selection. A mapping value ofNoneselects every streamable array and table key in that stream. An outerNoneselects every event stream and all its streamable array and table keys. Ragged and bytes nodes are ignored. metadata_filter : Callable[[Mapping[str, Any]], bool] or None, optional Predicate applied to the raw run-creation update’s persistedmetadata["start"]mapping. required_specs : str, iterable of str, or None, optional One spec name or every spec name required for a run to match. run_filter : Callable[[LiveChildCreated], bool] or None, optional Predicate applied to the raw Tiled run-creation update. start : int or None, optional Tiled sequence number supplied to every owned subscription. The default,0, replays records retained by the streaming cache.Nonereceives only new records. max_size : int, optional Maximum incoming WebSocket message size in bytes. Defaults to1_000_000.Returns
BlueskyStreamSubscription A running managed subscription. Use :meth:
~BlueskyStreamSubscription.disconnector a context manager to release it.Raises
ValueError If
streamsis an empty mapping or any data-key selection is an explicit empty iterable. Exception Any error raised while Tiled establishes the root subscription.Notes
The optional filters are evaluated in
metadata_filter,required_specs, thenrun_filterorder with short-circuiting AND semantics.The root container subscription is connected before this function returns. Updates from different data nodes or event streams have no global ordering, and Tiled may invoke the callback concurrently. Co-located selected table columns remain one native table update; this function does not join or align updates across nodes or streams.
With Tiled 0.2.18, the server can stream ragged nodes, but
RaggedClienthas no subscription API and the client has no ragged live schema or update model.BytesClientlikewise has no subscription API, and the server has no bytes live schema or cache emitter and rejects bytes on its single-node streaming route. Both families are ignored here.Examples
def on_update(update): … print(update.stream_name, update.data()) … subscription = subscribe_to_streams( … container, … on_update, … streams={“baseline”: (“x”, “y”), “primary”: None}, … ) subscription.disconnect()