djangordf.namespaces

The LangString dataclass plus the process-wide NamespaceRegistry that resolves CURIEs to URIRef objects.

Namespace utilities for djangordf.

Holds the LangString dataclass (used by LangStringProperty) and the process-wide NamespaceRegistry — a thin wrapper over rdflib namespaces that gives users a single place to register prefix bindings and a single resolve() that converts CURIEs into URIRef objects.

class djangordf.namespaces.LangString(value, lang)[source]

Bases: object

A language-tagged literal, paired with a BCP 47 language tag.

Used by LangStringProperty to round-trip rdf:langString values cleanly between Python and the triple store.

Parameters:
value: str
lang: str
class djangordf.namespaces.NamespaceRegistry[source]

Bases: object

Per-process registry of prefix -> namespace bindings.

Seeded with the common RDF/OWL/SKOS/Dublin Core/FOAF prefixes; extended through register() (typically from settings.DJANGORDF_NAMESPACES via apply_namespace_settings).

register(prefix, uri)[source]

Add or overwrite a prefix binding.

Raw strings are wrapped in rdflib.Namespace so concatenation produces URIRef objects with no extra ceremony.

Return type:

None

Parameters:
bindings()[source]

Snapshot of current prefix -> namespace bindings.

Return type:

Dict[str, Namespace]

bind_to_graph(graph)[source]

Bind every prefix in this registry on graph so its Turtle output uses pretty prefixes instead of full IRIs.

Return type:

None

Parameters:

graph (Graph)

resolve(value)[source]

Turn a CURIE ("skos:Concept") or a full IRI into a URIRef. Full IRIs pass straight through. Unknown prefixes raise ValueError so misconfiguration is loud.

Return type:

URIRef

djangordf.namespaces.apply_namespace_settings(extra=None)[source]

Feed settings.DJANGORDF_NAMESPACES (or the extra dict for tests) into the module-level registry.

Safe to call before Django is configured: if settings access raises ImproperlyConfigured and no explicit extra was given, this is a no-op.

Return type:

None

Parameters:

extra (Dict[str, str] | None)