middleware.common

Small shared helpers for middleware implementations.

Functions

copy_graph(→ rdflib.Graph)

Return an new copy of a graph in O(triples) time.

copy_dataset(→ rdflib.Dataset)

Return an new copy of a dataset in O(quads) time.

not_none(→ T)

Return value or raise ValueError when it is None.

Module Contents

middleware.common.copy_graph(source_graph: rdflib.Graph) → rdflib.Graph

Return an new copy of a graph in O(triples) time.

The new graph is backed by a rdflib.plugins.stores.memory.Memory store. Be aware of the size of your source_graph before invoking this function. Aside from the store, the returned graph replicates all of the source graph’s properties: namespace bindings, base URI, identifier, and triples.

middleware.common.copy_dataset(source_dataset: rdflib.Dataset) → rdflib.Dataset

Return an new copy of a dataset in O(quads) time.

The new dataset is backed by a rdflib.plugins.stores.memory.Memory store. Be aware of the size of your source_dataset before invoking this function. Aside from the store, the returned dataset replicates all of the source dataset’s properties: namespace bindings, default graph base URI, and quads.

middleware.common.not_none[T](value: T | None, message: str = 'Value cannot be None') → T

Return value or raise ValueError when it is None.