Skip to content


Subversion checkout URL

You can clone with
Download ZIP
surf SPARQL protocol plugin for the Virtuoso backend
Latest commit 74b3d6e Christoph Burgmer Use plug-in unit tests as shipped with new SuRF


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


Something went wrong with that request. Please try again.