Skip to content

Mapping API

Generated from docstrings. For mapper DSL and cascade policies, see SPECS.md and cascade policies.

OntoMapper

ontosql.mapping.mapper.OntoMapper

Bases: Generic[E]

Declares how a semantic entity maps to SQL tables.

metadata classmethod

metadata() -> MapperMetadataView

Neutral metadata view for RDF/import/sync layers.

Map factory

ontosql.mapping.map.Map

Factory for column and nested map bindings (delegates to module functions).

CascadePolicy

ontosql.mapping.cascade.CascadePolicy

Bases: str, Enum

Explicit nested save behavior on Map.nested.

Map helpers

ontosql.mapping.map.column

column(col: ColumnElement[Any], *, property: str | None = None, field: str | None = None) -> ColumnMap

Map a semantic field to a SQL column (preferred over Map(...)).

ontosql.mapping.map.nested

nested(entity_type: type[Any], *, join: ColumnElement[bool], nested_map: type[Any], property: str | None = None, field: str | None = None, target: Any = None, cascade: CascadePolicy = CascadePolicy.LINK, fk_column: ColumnElement[Any] | None = None) -> NestedMap

Map a nested semantic entity (preferred over Map.nested).

ontosql.mapping.map.computed

computed(expression: ColumnElement[Any], *, field: str, property: str | None = None) -> ComputedMap

Map a read-only computed field (preferred over Map.computed).

ontosql.mapping.map.collection

collection(entity_type: type[Any], *, through: Any, source_fk: ColumnElement[Any], target_fk: ColumnElement[Any], nested_map: type[Any], property: str | None = None, field: str | None = None, cascade: CascadePolicy = CascadePolicy.LINK) -> CollectionMap

Map a many-to-many collection (preferred over Map.collection).

Semantic models

ontosql.semantic.model.OntoModel

Bases: BaseModel

Base class for semantic entities.

jsonld_context class-attribute

jsonld_context: dict[str, Any] | None = None

Optional JSON-LD @context for list/export endpoints (see SPECS).

to_jsonld

to_jsonld(registry: PrefixRegistry | None = None) -> dict[str, Any]

Export this instance as a JSON-LD document (via ontosql.io).

to_rdf

to_rdf(*, format: str = 'turtle', registry: PrefixRegistry | None = None) -> str

Export this instance as an RDF serialization (via ontosql.io).

from_jsonld classmethod

from_jsonld(doc: dict[str, Any], *, mapper: type[Any], registry: PrefixRegistry | None = None) -> OntoModel

Hydrate an instance from a JSON-LD document using a mapper (via ontosql.io).

ontosql.semantic.model.onto_property

onto_property(curie: str, *, datatype: str | None = None, iri: str | None = None, language: str | None = None, **field_kwargs: Any) -> Any

Attach ontology metadata to a semantic model field.

PrefixRegistry

ontosql.registry.PrefixRegistry

Manage namespace prefixes for CURIEs and JSON-LD contexts.

curated classmethod

curated(bundle: str = 'schema_org', *, extra: dict[str, str] | None = None, vocab: str | None = None) -> PrefixRegistry

Build a registry from a curated vocabulary bundle.

with_prefix

with_prefix(prefix: str, iri: str) -> PrefixRegistry

Return a new registry with an additional prefix (copy-on-write).

with_vocab

with_vocab(vocab: str) -> PrefixRegistry

Return a new registry with @vocab set.

freeze

freeze() -> PrefixRegistry

Return an immutable copy of this registry.

expand

expand(curie: str) -> str

Expand a CURIE (prefix:local) to a full IRI.

compact

compact(iri: str) -> str

Compact a full IRI to a CURIE when a known prefix matches.

context_dict

context_dict() -> dict[str, Any]

Build a JSON-LD @context object.

prefixes

prefixes() -> dict[str, str]

Return a copy of registered prefixes (without @vocab).