kapps_ogm.ogm#

class kapps_ogm.ogm.OGM(*, db: GraphDB, loader: LoaderStrategy | None = None, logger: Logger | None = None, naming_schema: Callable[[], str] | None = None, skolem_namespace: str = 'https://w3id.org/circularfactory/.well-known/genid/')[source]#

Bases: object

TODO: Docstring for OGM

get_class_spec(*, class_iri: IRI, class_scope: ClassScope | None = None, hydration_level: ClassHydrationLevel = ClassHydrationLevel.SCOPE) → ClassSpec[source]#

Resolve a ClassSpec for a given class IRI and ClassScope.

ClassScope defines selective hydration of nested properties.

create(*, class_iri: IRI, data: dict, class_scope: ClassScope | None = None, instance_iri: IRI | None = None, persist: bool = True, named_graph: str | IRI | None = None) → Node[source]#

Create a new Node instance with given data. :param class_iri: IRI of the class to instantiate :param class_scope: ClassScope defining the class and property structure :param data: Data dictionary for the instance (must conform to class_spec) :param instance_iri: Optional IRI for the new instance (if not provided, a new one will be generated) :param persist: Whether to persist the new instance to the graph database

Returns:

Node representing the newly created instance

This is the primary entry point for: - REST POST - API writes - JSON import

create_blank_instance(*, class_iri: IRI, class_scope: ClassScope | None = None, instance_iri: IRI | None = None) → BaseModel[source]#

Create a blank pydantic instance for a given ClassScope, able to serve as a template for data population.

Parameters:
  • class_iri – IRI of the class to instantiate

  • class_scope – ClassScope defining the class and property structure

  • instance_iri – Optional IRI for the new instance

Returns:

pydantic BaseModel representing the blank instance

fetch(*, instance_iri: IRI, class_spec: ClassSpec | None = None, class_scope: ClassScope | None = None, as_reference: bool = False, materialize: bool = False) → Node[source]#

Fetch an existing RDF instance from the database and return a Node for that instance.

Parameters:
  • instance_iri – IRI of the instance to fetch

  • class_spec – Optional ClassSpec to use for fetching. If not provided, it will be resolved automatically

  • class_scope – Optional ClassScope for selective hydration

  • as_reference – If True, fetch only the IRI without loading properties

  • materialize – If True, materialize the Node’s data according to the ClassSpec. Ignored if as_reference is True.

Returns:

Node representing the fetched instance

Raises:

AnonymousNodeFetchError – If instance_iri is a Skolem IRI. Such a node is anonymous: nothing is asserted about it, so it has no rdf:type to resolve a ClassSpec from, and it is only meaningful as part of the entity that carries it.

commit(*, instance_iri: IRI, data: dict, named_graph: str | IRI | None = None) → Node[source]#

Update a Node instance with given data. :param instance_iri: IRI of the instance to update :param data: Data dictionary for the instance (must conform to class_spec) :param named_graph: Optional named graph to persist the changes to

Returns:

Node representing the newly updated instance

delete(*, node: Node) → bool[source]#

Delete an existing Node instance from the graph database.

Parameters:

node – Node instance to delete

Returns:

True if deletion was successful, False otherwise

Return type:

bool