Types¶
Haystack value types and the server operations layer.
Kinds¶
Haystack value types as frozen dataclasses. Includes Marker,
Number, Ref,
Coord, Symbol,
Uri, XStr,
Na, and Remove
with singleton instances MARKER, NA, and REMOVE.
Haystack data type kinds.
Implements all Project Haystack scalar and singleton value types as immutable Python objects. Collection types (list, dict) and passthrough types (bool, str, datetime.date, datetime.time, datetime.datetime) use their native Python equivalents directly.
See: https://project-haystack.org/doc/docHaystack/Kinds
- class hs_py.kinds.Coord(lat, lng)[source]¶
Bases:
objectGeographic coordinate as latitude/longitude in decimal degrees.
- class hs_py.kinds.Marker[source]¶
Bases:
_SingletonMarker tag singleton.
Marker is a label type used to express typing information.
- Return type:
_Singleton
- class hs_py.kinds.Na[source]¶
Bases:
_SingletonNA (not available) singleton.
Represents missing or invalid data, analogous to R’s
NA.- Return type:
_Singleton
- class hs_py.kinds.Number(val, unit=None)[source]¶
Bases:
objectNumeric value with optional unit of measurement.
Supports special IEEE 754 values:
NaN,INF,-INF.
- class hs_py.kinds.Ref(val, dis=None)[source]¶
Bases:
objectEntity reference identifier.
valis an opaque identifier string containing only ASCII letters, digits, underbar, colon, dash, period, and tilde.
- class hs_py.kinds.Remove[source]¶
Bases:
_SingletonRemove singleton.
Indicates a tag should be removed from a dict.
- Return type:
_Singleton
- class hs_py.kinds.Symbol(val)[source]¶
Bases:
objectDefinition name constant (e.g.
^elec-meter).- Parameters:
val (str)
- class hs_py.kinds.Uri(val)[source]¶
Bases:
objectUniversal Resource Identifier per RFC 3986.
- Parameters:
val (str)
- class hs_py.kinds.XStr(type_name, val)[source]¶
Bases:
objectExtended string: a typed string tuple.
type_namemust start with an uppercase ASCII letter.
Watch¶
Watch state tracking and delta encoding for subscription-based data updates.
Watch state tracking with delta encoding and server-side filtering.
Provides WatchState for server-side delta computation and
WatchAccumulator for client-side delta merging. Both classes
track entity state per watch subscription to minimise push payload size.
Server-side filtering evaluates a Haystack filter expression against entities before pushing, so clients only receive matching changes.
- class hs_py.watch.WatchAccumulator[source]¶
Bases:
objectClient-side state accumulator for delta watch pushes.
Merges incoming delta grids into a full entity state cache.
- class hs_py.watch.WatchState(watch_id, *, filter_ast=None)[source]¶
Bases:
objectServer-side entity state tracker for a single watch.
Maintains a cache of the last-sent entity state so that
compute_delta()can emit only changed, new, or removed tags on each push cycle.- Parameters:
- compute_delta(current)[source]¶
Compute a delta grid from the current full state.
New entities (not in cache) are included in full.
Changed tags are included with their new values.
Removed tags are represented as
REMOVE.Entities in the cache but absent from current get an
_removedmarker row.
- update(current)[source]¶
Update the cache with the current full entity state.
Call this after
compute_delta()to keep the cache in sync.
Ops¶
Server-side Haystack operation dispatch layer.
Haystack server operations base class and op registry.
Provides HaystackOps, the abstract base for all server-side
operation dispatchers, and the op-name-to-method-name mappings used
by HTTP and WebSocket handlers.
- class hs_py.ops.HaystackOps(storage=None, namespace=None)[source]¶
Bases:
objectBase class for Haystack server operations.
Subclass and override the operations you support. When a storage adapter is provided the base-class implementations automatically parse the request
Grid, delegate to the adapter, and wrap the result back into a Grid. Without an adapter, unimplemented POST ops return an error grid. Theops()andformats()methods have useful defaults.- Parameters:
storage (StorageAdapter | None)
namespace (Namespace | None)
- async about()[source]¶
Return server information.
The default implementation returns minimal metadata. Subclasses may override this to include richer details such as
serverNameorvendorUri.- Return type:
- async ops()[source]¶
Return the list of supported operations.
Auto-discovers which methods the subclass has overridden, plus storage-backed ops (when a storage adapter is present) and namespace-backed ops (when a namespace is present).
- Return type:
- async formats()[source]¶
Return supported data formats per Haystack filetypes op.
Reports all MIME types this server can send and/or receive.
- Return type: