RDFLib provides an
abstracted Store API
for persistence of RDF and Notation 3. The
Graph class works with instances of this API
(as the first argument to its constructor) for triple-based management
of an RDF store including: garbage collection, transaction management,
update, pattern matching, removal, length, and database management
Additional persistence mechanisms can be supported by implementing this API for a different store.
Stores currently shipped with core RDFLib¶
In most cases, passing the name of the store to the Graph constructor is enough:
from rdflib import Graph graph = Graph(store='BerkeleyDB')
Most stores offering on-disk persistence will need to be opened before reading or writing. When peristing a triplestore, rather than a ConjuntiveGraph quadstore, you need to specify an identifier with which you can open the graph:
graph = Graph('BerkeleyDB', identifier='mygraph') # first time create the store: graph.open('/home/user/data/myRDFLibStore', create=True) # work with the graph: data = """ PREFIX : <https://example.org/> :a :b :c . :d :e :f . :d :g :h . """ graph.parse(data=data, format="ttl") # when done! graph.close()
close() must be called to free the resources associated with the store.
Additional store plugins¶
More store implementations are available in RDFLib extension projects: