Virtuoso support for RDFLib

There is now some rudimentary support for a Virtuoso backed store in RDFLib. Basic usage is as follows:

from rdflib.store import Store
from rdflib.plugin import get as plugin

Virtuoso = plugin("Virtuoso", Store)
store = Virtuoso("DSN=VOS;UID=dba;PWD=dba;WideAsUTF16=Y")

and then use this store as you would any other. This has been tested with rdflib3 only and may or may not work with rdflib2.

With RDFLib 3 there is support for using Virtuoso’s SPARQL directly from the Graph.query. There are some outstanding questions about how this will behave with multiple sparql implementations...

NOTE the way Virtuoso handles cursors might be unexpected. A store will acquire a cursor on demand but when operations with it have finished it is important to release it. This is done by calling the graph (or the store)’s commit or rollback methods. Be sure to do this frequently especially for long running processes that may keep a store around for long periods of time.

Virtuoso Storage

class virtuoso.vstore.Virtuoso(*av, **kw)[source]

RDFLib Storage backed by Virtuoso

cursor(isolation='READ COMMITTED')

Acquire a cursor, setting the isolation level.

query(q, cursor=None, *av, **kw)[source]

Run a SQL query on the connection optionally with the supplied cursor. If the cursor is not specified one will be allocated and kept until commit() or rollback() is called.

sparql_query(q, *av, **kw)[source]

Run a SPARQL query on the connection. Returns a Graph in case of DESCRIBE or CONSTRUCT, a bool in case of Ask and a generator over the results otherwise.

commit()[source]

Commit any pending work. Also releases the cached cursor.

rollback()[source]

Roll back any pending work. Also releases the cached cursor.

SPASQL Resolution

virtuoso.vstore.resolve(resolver, args)[source]

Takes the Virtuoso representation of an RDF node and returns an appropriate instance of rdflib.term.Node.

Parameters:
  • resolver – an cursor that can be used for database queries necessary to resolve the value
  • args – the tuple returned by pyodbc in case of a SPASQL query.

Table Of Contents

Previous topic

Virtuoso Support for SQLAlchemy

This Page