Shapes & Validation¶
SHACL-grade shape declaration system for Trails.
Auto-generated docs
When trails is installed, run ENABLE_MKDOCSTRINGS=true ./scripts/docs-build
for full docstring-extracted reference.
Decorators and helpers¶
| Symbol | Signature | Description |
|---|---|---|
@shape |
@shape(_cls_or_iri=None, *, iri: str \| None = None, extends: list[str] \| None = None, prefixes: dict[str, str] \| None = None) |
Register a class as a Trails shape. Supports bare (@shape), positional IRI, or keyword forms |
predicate |
predicate(iri: str, *, min: int \| None = None, max: int \| None = None, required: bool \| None = None, many: bool \| None = None, one_of: list \| None = None, min_value: number \| None = None, max_value: number \| None = None, pattern: str \| None = None, min_length: int \| None = None, max_length: int \| None = None) -> PredicateInfo |
Declare an RDF predicate binding for a shape field with SHACL-grade constraints |
Registry¶
| Symbol | Signature | Description |
|---|---|---|
get_shape |
get_shape(iri: str) -> ShapeMeta \| None |
Look up a registered shape by IRI |
list_shapes |
list_shapes() -> list[ShapeMeta] |
Return all registered shapes |
get_shapes_for_node_type |
get_shapes_for_node_type(node_type_iri: str) -> list[ShapeMeta] |
Return every @shape registered against a node-type IRI |
JSON Schema generation¶
| Symbol | Signature | Description |
|---|---|---|
shape_to_json_schema |
shape_to_json_schema(shape_id: str) -> dict |
Convert a registered @shape to a JSON Schema dict |
node_type_to_json_schema |
node_type_to_json_schema(cls: type) -> dict |
Convert a @node_type-decorated class to a JSON Schema dict |