Skip to content

API reference / Reading and ingest

tsdive.read_meta_json

read_meta_json(path: str | Path) -> TagMeta

Load a TagMeta from a JSON file.

The file uses the same object as the archive's own tsdive.meta block, so metadata written for ingest is readable back off the archive without a second format to keep in step.

Every key is checked, at the top level and under identity. A key tsdive does not read raises SchemaError naming the closest known key, so a misspelt "unit" cannot leave the archive without its unit.

Raises:

Type Description
SchemaError

invalid JSON, an unknown or missing key, a value of the wrong type, one end of the engineering range without the other, or a quality_codes entry that names no severity.

Examples:

>>> import json
>>> import tsdive
>>> meta = {"identity": {"source_id": "plant1", "point_id": "FIC101.PV"},
...         "name": "FIC-101 flow", "unit_raw": "m3/h", "sample_rate_s": 3.0}
>>> with open("FIC101.PV.json", "w", encoding="utf-8") as f:
...     json.dump(meta, f)
>>> read = tsdive.read_meta_json("FIC101.PV.json")
>>> str(read.identity), read.unit_raw, read.sample_rate_s
('plant1:FIC101.PV', 'm3/h', 3.0)

A misspelt key raises instead of being dropped:

>>> meta["unit"] = meta.pop("unit_raw")
>>> with open("FIC101.PV.json", "w", encoding="utf-8") as f:
...     json.dump(meta, f)
>>> tsdive.read_meta_json("FIC101.PV.json")
Traceback (most recent call last):
...
tsdive.errors.SchemaError: FIC101.PV.json: unknown key 'unit'; did you mean 'unit_raw'?