Schema Generation#

To allow for python typing of documents, we define them as TypedDict in event_model.documents.

# ruff: noqa
# generated by datamodel-codegen:
#   filename:  datum.json

from __future__ import annotations

from typing import Any, Dict, TypedDict


class Datum(TypedDict):
    """
    Document to reference a quanta of externally-stored data
    """

    datum_id: str
    """
    Globally unique identifier for this Datum (akin to 'uid' for other Document types), typically formatted as '<resource>/<integer>'
    """
    datum_kwargs: Dict[str, Any]
    """
    Arguments to pass to the Handler to retrieve one quanta of data
    """
    resource: str
    """
    The UID of the Resource to which this Datum belongs
    """

We then use pydantic to convert these python types into the jsonschema in event_model.schemas.

After changing any of the documents it’s necessary to regenerate the schemas. This can be done by running:

python -m event_model.generate

which is a python environment script in a dev install of event-model.

This ensures we can have accurate typing across the bluesky codebase, but also doesn’t limit us to python for validating documents.