surf SPARQL protocol plugin for the Virtuoso backend
Switch branches/tags
Nothing to show
Pull request Compare This branch is even with nwebs:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


surf.virtuoso_protocol is a plugin for the Python-based Object-RDF Mapper SuRF implementing the SPARQL protocol as used in the Virtuoso backend.


Use OWL sameAs:

>>> import surf
>>> # Create store & session
... store = surf.Store(reader="virtuoso_protocol",
...                    writer="virtuoso_protocol",
...                    endpoint="http://localhost:8890/sparql",
...                    default_context="http://dummy")
>>> session = surf.Session(store, {})
>>> # John
... Person = session.get_class(surf.ns.FOAF["Person"])
>>> john = session.get_resource("http://John", Person)
>>> john.foaf_name = 'John'
>>> # Jonathan
... jonathan = session.get_resource("http://Jonathan", Person)
>>> jonathan.foaf_homepage = ''
>>> # owl:sameAs
... john[surf.ns.OWL['sameAs']] = jonathan
>>> session.commit()
>>> # Set owl:sameAs Inferencing
... store.reader.define = 'input:same-as "yes"'
>>> # Query
... query ="?s").from_("http://dummy")\
...                   .where((jonathan.subject, surf.ns.FOAF['name'], '?s'))
>>> store.execute_sparql(unicode(query))
{'results': {'bindings': [{'s': rdflib.Literal(u'John')}]}}


Virtuoso can be accessed via SuRF's sparql_protocol handler. However, for making use of Virtuoso's inferencing & reasoning support a specialized SPARQL syntax is needed, which this plugin can accommodate. Technically this plugin extends SuRF's sparql_protocol plugin with functionality needed for Virtuoso.

Default write context

Virtuoso's graph implementation knows multiple named graphs and one unnamed graph. The unnamed graph built up from the union of all named graphs during SPARQL queries. For SPARUL (write access) a named graph needs to be given as context. The virtuoso_protocol plugin introduces a default_write_context parameter to provide a default context for write access. In contrast to SuRF's default_context the application of a write-only context allows for queries over all named graphs at once, while still being able to issue writes to a dedicated named graph.

Unit testing


$ python nosetests

Similar packages

  • surf.sparql_protocol - SuRF SPARQL protocol plugin (mentioned above), allows access to Virtuoso's standard SPARQL features.
  • Python-Virtuoso - OpenLink Virtuoso Support for SQLAlchemy and RDFLib,, provides access through ODBC