Define a schema from Python
Prerequisites
panproto installed (Install the Python SDK).
The task
import panproto
proto = panproto.get_builtin_protocol("atproto")
b = proto.schema()
b.vertex("user", "object", "app.example.user")
b.vertex("user:name", "string")
b.vertex("user:age", "integer")
b.edge("user", "user:name", "prop", "name")
b.edge("user", "user:age", "prop", "age")
schema = b.build()
panproto.get_builtin_protocol(name) returns the named protocol; .vertex(id, kind, nsid=None) and .edge(src, tgt, kind, name=None) each mutate the SchemaBuilder in place (returning None), and .build() validates and returns a Schema. The TypeScript SDK exposes the same operations as a chainable surface; the Python binding does not.
Call panproto.list_builtin_protocols() to see the registered protocol names. Treat the returned list as the source of truth rather than hard-coding a catalog count.
Verification
issues = schema.validate(proto)
assert not issues, issues
Schema.validate(protocol) returns protocol-level structural validation messages. An empty list means no vertex-kind, edge-rule, constraint-sort, required-edge, or recursion-reference error was found; it does not run equation checking.
Common mistakes
- Chaining the builder calls. The Python
SchemaBuilder.vertex(...)/edge(...)/constraint(...)methods mutate in place and returnNone; hold the builder in a variable and mutate it statement-by-statement, then call.build(). - Using a Python dict where the SDK expects a
Schemahandle. Conversion is deliberate; to materialize anInstancefrom bytes against a builtSchema, usepanproto.IoRegistry().parse(protocol, schema, data).