djangordf.backends¶
Triple-store backend abstraction.
Base¶
Abstract base class every triple-store backend must implement.
- class djangordf.backends.base.TripleStoreBackend[source]¶
Bases:
ABCThe contract a triple-store backend must fulfil.
Intentionally narrow: SPARQL 1.1 query and update plus convenience helpers for bulk add, pattern-based remove, and clearing a graph. Anything beyond (transactions, reasoning, named-graph listing) is opt-in via subclass extension.
- abstractmethod query(sparql)[source]¶
Run a SPARQL SELECT, ASK, CONSTRUCT or DESCRIBE.
Returns an rdflib
Graphfor CONSTRUCT/DESCRIBE and an rdflibResultfor SELECT/ASK.
- abstractmethod update(sparql)[source]¶
Run a SPARQL UPDATE (INSERT, DELETE, CLEAR, LOAD).
Backends may return any value that helps callers reason about the outcome: HTTP-talking backends return the underlying
requests.Responseso callers can read the status code or custom headers; in-process backends typically returnNone.- Parameters:
sparql (str)
- abstractmethod add(triples, graph=None)[source]¶
Bulk-add triples to a named graph, or the default graph if
graphisNone.
In-memory backend¶
In-memory triple-store backend using rdflib’s ConjunctiveGraph.
- class djangordf.backends.memory.InMemoryBackend[source]¶
Bases:
TripleStoreBackendTriple-store backend that keeps all data in process memory.
Powers unit tests and the local quickstart. SPARQL queries and updates are dispatched directly to rdflib’s own engine.
- query(sparql)[source]¶
Run a SPARQL SELECT, ASK, CONSTRUCT or DESCRIBE.
Returns an rdflib
Graphfor CONSTRUCT/DESCRIBE and an rdflibResultfor SELECT/ASK.
- update(sparql)[source]¶
Run a SPARQL UPDATE (INSERT, DELETE, CLEAR, LOAD).
Backends may return any value that helps callers reason about the outcome: HTTP-talking backends return the underlying
requests.Responseso callers can read the status code or custom headers; in-process backends typically returnNone.
- add(triples, graph=None)[source]¶
Bulk-add triples to a named graph, or the default graph if
graphisNone.
Fuseki backend¶
SPARQL 1.1 HTTP triple-store backend for Apache Jena Fuseki and similar.
- class djangordf.backends.fuseki.FusekiBackend(endpoint, user=None, password=None)[source]¶
Bases:
TripleStoreBackendTriple-store backend that talks SPARQL 1.1 HTTP to a remote endpoint.
Compatible with Apache Jena Fuseki and any other store that implements the SPARQL 1.1 Protocol (Blazegraph, GraphDB, Stardog).
- query(sparql)[source]¶
Run a SPARQL SELECT, ASK, CONSTRUCT or DESCRIBE.
Returns an rdflib
Graphfor CONSTRUCT/DESCRIBE and an rdflibResultfor SELECT/ASK.
- update(sparql)[source]¶
POST
sparqlto the Fuseki update endpoint.Returns the underlying
requests.Responseso callers can distinguish 200 vs. 204 outcomes, inspect custom headers, or log the body — mirroring howquery()returns a graph or result for callers to consume.raise_for_statushas already been called inside_post, so any 4xx/5xx surface asrequests.HTTPErrorbefore this returns.
- add(triples, graph=None)[source]¶
Bulk-add triples to a named graph, or the default graph if
graphisNone.