djangordf.backends

Triple-store backend abstraction.

Base

Abstract base class every triple-store backend must implement.

class djangordf.backends.base.TripleStoreBackend[source]

Bases: ABC

The 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 Graph for CONSTRUCT/DESCRIBE and an rdflib Result for SELECT/ASK.

Return type:

Union[Result, Graph]

Parameters:

sparql (str)

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.Response so callers can read the status code or custom headers; in-process backends typically return None.

Parameters:

sparql (str)

abstractmethod add(triples, graph=None)[source]

Bulk-add triples to a named graph, or the default graph if graph is None.

Return type:

None

Parameters:
abstractmethod remove(pattern, graph=None)[source]

Remove all triples matching (s, p, o) where any element may be None to act as a wildcard.

Return type:

None

Parameters:
abstractmethod clear(graph=None)[source]

Remove all triples from a named graph, or from the default graph if graph is None.

Return type:

None

Parameters:

graph (URIRef | None)

In-memory backend

In-memory triple-store backend using rdflib’s ConjunctiveGraph.

class djangordf.backends.memory.InMemoryBackend[source]

Bases: TripleStoreBackend

Triple-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 Graph for CONSTRUCT/DESCRIBE and an rdflib Result for SELECT/ASK.

Return type:

Union[Result, Graph]

Parameters:

sparql (str)

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.Response so callers can read the status code or custom headers; in-process backends typically return None.

Return type:

None

Parameters:

sparql (str)

add(triples, graph=None)[source]

Bulk-add triples to a named graph, or the default graph if graph is None.

Return type:

None

Parameters:
remove(pattern, graph=None)[source]

Remove all triples matching (s, p, o) where any element may be None to act as a wildcard.

Return type:

None

Parameters:
clear(graph=None)[source]

Remove all triples from a named graph, or from the default graph if graph is None.

Return type:

None

Parameters:

graph (URIRef | None)

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: TripleStoreBackend

Triple-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).

Parameters:
  • endpoint (str)

  • user (str | None)

  • password (str | None)

query(sparql)[source]

Run a SPARQL SELECT, ASK, CONSTRUCT or DESCRIBE.

Returns an rdflib Graph for CONSTRUCT/DESCRIBE and an rdflib Result for SELECT/ASK.

update(sparql)[source]

POST sparql to the Fuseki update endpoint.

Returns the underlying requests.Response so callers can distinguish 200 vs. 204 outcomes, inspect custom headers, or log the body — mirroring how query() returns a graph or result for callers to consume. raise_for_status has already been called inside _post, so any 4xx/5xx surface as requests.HTTPError before this returns.

add(triples, graph=None)[source]

Bulk-add triples to a named graph, or the default graph if graph is None.

remove(pattern, graph=None)[source]

Remove all triples matching (s, p, o) where any element may be None to act as a wildcard.

clear(graph=None)[source]

Remove all triples from a named graph, or from the default graph if graph is None.