Inferring a schema
Draft a schema from example documents instead of writing one by hand.
infer(samples) drafts a schema mechanically from a list of example Documents:
from omnist import infer, doc
s = infer([doc({"id": 1, "tags": ["a"]}), doc({"id": 2, "tags": ["b", "c"]})])
print(s.to_osd())Output
record Root {
"id": integer,
"tags" [0,]: string,
}
root Rootinfer returns the raw mechanical inference — it does not normalize. Nested-record names stay 1:1 with the sample's own labels, so structurally-identical shapes under different labels come out as duplicate records. Call .normalize() on the result where a canonical minimal schema is wanted.