store
Types of store
Context-aware: An RDF store capable of storing statements within contexts
is considered context-aware. Essentially, such a store is able to partition
the RDF model it represents into individual, named, and addressable
sub-graphs.
Relevant Notation3 reference regarding formulae, quoted statements, and such: http://www.w3.org/DesignIssues/Notation3.html
Formula-aware: An RDF store capable of distinguishing between statements
that are asserted and statements that are quoted is considered formula-aware.
Transaction-capable: capable of providing transactional integrity to the
RDF operations performed on it.
Graph-aware: capable of keeping track of empty graphs.
Classes:
-
NodePickler– -
Store– -
StoreCreatedEvent–This event is fired when the Store is created.
-
TripleAddedEvent–This event is fired when a triple is added.
-
TripleRemovedEvent–This event is fired when a triple is removed.
__all__
module-attribute
NodePickler
Methods:
-
__getstate__– -
__setstate__– -
dumps– -
loads– -
register–
Source code in rdflib/store.py
__getstate__
__setstate__
dumps
dumps(obj: Node, protocol: Optional[Any] = None, bin: Optional[Any] = None)
Source code in rdflib/store.py
loads
loads(s: bytes) -> Node
Source code in rdflib/store.py
Store
Store(configuration: Optional[str] = None, identifier: Optional[Identifier] = None)
Parameters:
-
(identifierOptional[Identifier], default:None) –URIRef of the Store. Defaults to CWD
-
(configurationOptional[str], default:None) –String containing information open can use to connect to datastore.
Methods:
-
__len__–Number of statements in the store. This should only account for non-
-
add–Adds the given statement to a specific context or to the model.
-
addN–Adds each item in the list of statements to a specific context.
-
add_graph–Add a graph to the store, no effect if the graph already
-
bind–Bind a namespace to a prefix.
-
close–Closes the database connection.
-
commit– -
contexts–Generator over all contexts in the graph. If triple is specified,
-
create– -
destroy–Destroys the instance of the store.
-
gc–Allows the store to perform any needed garbage collection.
-
namespace– -
namespaces– -
open–Opens the store specified by the configuration string.
-
prefix– -
query–If stores provide their own SPARQL implementation, override this.
-
remove–Remove the set of triples matching the pattern from the store
-
remove_graph–Remove a graph from the store, this should also remove all
-
rollback– -
triples–A generator over all the triples matching the pattern. Pattern can
-
triples_choices–A variant of triples that can take a list of terms instead of a single
-
update–If stores provide their own (SPARQL) Update implementation, override this.
Attributes:
-
context_aware(bool) – -
dispatcher– -
formula_aware(bool) – -
graph_aware(bool) – -
node_pickler(NodePickler) – -
transaction_aware(bool) –
Source code in rdflib/store.py
__len__
__len__(context: Optional[_ContextType] = None) -> int
Number of statements in the store. This should only account for non- quoted (asserted) statements if the context is not specified, otherwise it should return the number of statements in the formula or context given.
Parameters:
-
(contextOptional[_ContextType], default:None) –a graph instance to query or None
Source code in rdflib/store.py
add
Adds the given statement to a specific context or to the model.
Parameters:
-
(triple_TripleType) –The triple to add
-
(context_ContextType) –The context to add the triple to
-
(quotedbool, default:False) –If True, indicates this statement is quoted/hypothetical (for formula-aware stores)
Note
It should be an error to not specify a context and have the quoted argument be True. It should also be an error for the quoted argument to be True when the store is not formula-aware.
Source code in rdflib/store.py
addN
addN(quads: Iterable[_QuadType]) -> None
Adds each item in the list of statements to a specific context.
The quoted argument is interpreted by formula-aware stores to indicate this statement is quoted/hypothetical.
Note
The default implementation is a redirect to add.
Parameters:
-
(quadsIterable[_QuadType]) –An iterable of quads to add
Source code in rdflib/store.py
add_graph
Add a graph to the store, no effect if the graph already exists.
Parameters:
-
(graphGraph) –a Graph instance
bind
Bind a namespace to a prefix.
Parameters:
-
(prefixstr) –The prefix to bind the namespace to.
-
(namespaceURIRef) –The URIRef of the namespace to bind.
-
(overridebool, default:True) –If True, rebind even if the given namespace is already bound to another prefix
Source code in rdflib/store.py
close
close(commit_pending_transaction: bool = False) -> None
Closes the database connection.
Parameters:
-
(commit_pending_transactionbool, default:False) –Whether to commit all pending transactions before closing (if the store is transactional).
contexts
Generator over all contexts in the graph. If triple is specified, a generator over all contexts the triple is in.
if store is graph_aware, may also return empty contexts
:returns: a generator over Nodes
Source code in rdflib/store.py
create
destroy
destroy(configuration: str) -> None
Destroys the instance of the store.
Parameters:
-
(configurationstr) –The configuration string identifying the store instance.
gc
namespace
namespace(prefix: str) -> Optional[URIRef]
namespaces
namespaces() -> Iterator[Tuple[str, URIRef]]
Source code in rdflib/store.py
open
open(configuration: Union[str, tuple[str, str]], create: bool = False) -> Optional[int]
Opens the store specified by the configuration string.
Parameters:
-
(configurationUnion[str, tuple[str, str]]) –Store configuration string
-
(createbool, default:False) –If True, a store will be created if it doesn’t exist. If False and the store doesn’t exist, an exception is raised.
Returns:
-
Optional[int]–One of: VALID_STORE, CORRUPTED_STORE, or NO_STORE
Raises:
-
Exception–If there are insufficient permissions to open the store.
Source code in rdflib/store.py
prefix
prefix(namespace: URIRef) -> Optional[str]
query
query(query: Union[Query, str], initNs: Mapping[str, Any], initBindings: Mapping[str, Identifier], queryGraph: str, **kwargs: Any) -> Result
If stores provide their own SPARQL implementation, override this.
queryGraph is None, a URIRef or __UNION__
If None the graph is specified in the query-string/object
If URIRef it specifies the graph to query,
If __UNION__ the union of all named graphs should be queried
(This is used by ConjunctiveGraphs
Values other than None obviously only makes sense for
context-aware stores.)
Source code in rdflib/store.py
remove
Remove the set of triples matching the pattern from the store
remove_graph
remove_graph(graph: Graph) -> None
Remove a graph from the store, this should also remove all triples in the graph
Parameters:
-
–graphida Graph instance
rollback
triples
triples(triple_pattern: _TriplePatternType, context: Optional[_ContextType] = None) -> Iterator[Tuple[_TripleType, Iterator[Optional[_ContextType]]]]
A generator over all the triples matching the pattern. Pattern can include any objects for used for comparing against nodes in the store, for example, REGEXTerm, URIRef, Literal, BNode, Variable, Graph, QuotedGraph, Date? DateRange?
Parameters:
-
(contextOptional[_ContextType], default:None) –A conjunctive query can be indicated by either providing a value of None, or a specific context can be queries by passing a Graph instance (if store is context aware).
Source code in rdflib/store.py
triples_choices
triples_choices(triple: _TripleChoiceType, context: Optional[_ContextType] = None) -> Generator[Tuple[_TripleType, Iterator[Optional[_ContextType]]], None, None]
A variant of triples that can take a list of terms instead of a single term in any slot. Stores can implement this to optimize the response time from the default ‘fallback’ implementation, which will iterate over each term in the list and dispatch to triples
Source code in rdflib/store.py
update
update(update: Union[Update, str], initNs: Mapping[str, Any], initBindings: Mapping[str, Identifier], queryGraph: str, **kwargs: Any) -> None
If stores provide their own (SPARQL) Update implementation, override this.
queryGraph is None, a URIRef or __UNION__
If None the graph is specified in the query-string/object
If URIRef it specifies the graph to query,
If __UNION__ the union of all named graphs should be queried
(This is used by ConjunctiveGraphs
Values other than None obviously only makes sense for
context-aware stores.)
Source code in rdflib/store.py
StoreCreatedEvent
TripleAddedEvent
TripleRemovedEvent
Bases: Event
This event is fired when a triple is removed.
Attributes:
-
triple–The triple removed from the graph.
-
context–The context of the triple, if any.
-
graph–The graph from which the triple was removed.