Event Model
raw JSON → 1.23.1 verified Fri May 01 auth: no python
Data model used by the bluesky ecosystem. Defines schemas for experimental data documents (e.g., Event, EventDescriptor, RunStart). Currently at version 1.23.1, released on a monthly cadence.
pip install event-model Common errors
error ImportError: cannot import name 'Event' from 'event_model.schemas' ↓
cause Event is exported from the top-level event_model package, not from event_model.schemas.
fix
Use: from event_model import Event
error AttributeError: 'Event' object has no attribute 'dict' ↓
cause In v1.23, Event is a TypedDict, not a pydantic BaseModel. pydantic's .dict() is not available.
fix
Use: dict(event) or copy with dict(event)
error ValidationError: 1 validation error for DataKey precision none is not an allowed value (type=type_error.none.not_allowed) ↓
cause In v1.22.0+, DataKey fields like 'precision' cannot be None; omit the key if not needed.
fix
Remove the field or use a valid value.
Warnings
breaking In v1.23, the internal representation changed from pydantic BaseModel to jsonschema + TypedDict. Code that relied on pydantic methods (e.g., .dict(), .copy()) will break. Use dict() and copy from the TypedDict protocol instead. ↓
fix Replace .dict() with dict(doc) and .copy() with dict(doc); avoid pydantic-specific features.
breaking In v1.21, StreamResource and StreamDatum schemas changed significantly: `path_semantics` and `resource_kwargs` removed; `uri`, `parameters`, and `mimetype` added. ↓
fix Update code that creates StreamResource/StreamDatum to use new fields; drop old fields.
gotcha In v1.22.0, DataKey fields `precision`, `choices`, and `units` became required (non-optional). Leaving them out is still allowed, but providing None raises a validation error. ↓
fix Remove None values from those fields; omit the keys entirely if not needed.
Imports
- Event wrong
from event_model.schemas import Eventcorrectfrom event_model import Event - RunStart wrong
from bluesky_models import RunStartcorrectfrom event_model import RunStart - EventDescriptor wrong
from bluesky import event_modelcorrectfrom event_model import EventDescriptor
Quickstart
from event_model import Event, RunStart
start = RunStart(
uid='abc123',
time=1640000000.0,
plan_name='scan',
scan_id=42
)
event = Event(
uid='def456',
time=1640000001.0,
descriptor_uid='ghi789',
seq_num=1,
data={'det': 3.14159},
timestamps={'det': 1640000001.0},
filled={}
)
print(start, event)