### Navigation

- index
- modules |
- next |
- previous |
- rdflib 4.1.2 documentation »

# Persistence

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 (`open()` / `close()` / `destroy()`).

Additional persistence mechanisms can be supported by implementing this API for a different store.

## Stores currently shipped with core RDFLib

- `Memory` (not persistent!)
- `Sleepycat` (on disk persistence via Python’s bsddb or bsddb3 packages)
- `SPARQLStore` - a read-only wrapper around a remote SPARQL Query endpoint.
- `SPARQLUpdateStore` - a read-write wrapper around a remote SPARQL query/update endpoint pair.

## Usage

Most cases passing the name of the store to the Graph constructor is enough:

    from rdflib import Graph

    graph = Graph(store='Sleepycat')

Most store offering on-disk persistence will need to be opened before reading or writing :

    graph = Graph('Sleepycat')

    # first time create the store:
    graph.open('/home/user/data/myRDFLibStore', create = True)

    # work with the graph:
    graph.add( mytriples )

    # when done!
    graph.close()

When done, `close()` must be called to free the resources associated with the store.

## Additional store plugins

More store implementations are available in RDFLib extension projects:

> - rdflib-sqlalchemy, which supports stored on a wide-variety of RDBMs backends,
> - rdflib-leveldb - a store on to of Google’s LevelDB key-value store.
> - rdflib-kyotocabinet - a store on to of the Kyoto Cabinet key-value store.

## Example

- `examples.sleepycat_example` contains an example for using a Sleepycat store.
- `examples.sparqlstore_example` contains an example for using a SPARQLStore.

### Navigation

- index
- modules |
- next |
- previous |
- rdflib 4.1.2 documentation »