Skip to main content


Project description


A SPARQL 1.1 implementation for RDFLib.

This replaces the old implementation available in RDFExtras, hopefully
with more maintainable code.

[![Build Status](](


Install with setuptools, either easy_install or pip will register the
SPARQL processor with RDFLib automatically. I cannot recommend this
strongly enough.

(you should also uninstall rdfextras - although my test with both
installed still gave me the NEW sparql implementation - but I belive
this was random, i.e. depending on a hash value of something)


g = rdflib.Graph()

for row in g.query(
'select ?s where { [] <> ?s .}'):
print row

Prepared Queries

Queries can be parsed/translated beforehand - and the initBindings
kwarg to graph.query can be used to fill in variables that are known:

# ./examples/

import rdflib
from rdflib_sparql.processor import prepareQuery

q = prepareQuery(
'select ?s where { ?person <> ?s .}')

g = rdflib.Graph()

tim = rdflib.URIRef("")

for row in g.query(q, initBindings={'person': tim}):
print row


Property Paths

SPARQL PropertyPaths are also available as "pseudo properties" in python
code. See docs in *rdflib_sparql/*

# ./examples/

g = Graph()

tim = URIRef("")

print("Timbl knows:")

# find name of everyone tim knows:
for o in g.objects(tim, FOAF.knows/
print o


SPARQL Update is implemented - but no HTTP/SPARQL Protocol yet.
SPARQL Update requests can be evaluated with

# ./examples/*

import rdflib
from rdflib_sparql.processor import processUpdate

g = rdflib.Graph()

processUpdate(g, '''
PREFIX foaf: <>
PREFIX dbpedia: <>
{ ?s a dbpedia:Human . }
{ ?s a foaf:Person . }

for x in g.subjects(



Currently about 90% of SPARQL 1.0 and SPARQL 1.1 Query tests pass. This
should be much better than the RDFExtras implementation.

For test results, see also:

So far, only functional testing has been done, i.e. performance may be rubbish.

If you would like to dig into the code, see DEVELOPERS

I would welcome any feedback on this!

- Gunnar

Project details

Release history Release notifications

This version
History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
rdflib-sparql-0.2.tar.gz (1.6 MB) Copy SHA256 hash SHA256 Source None Apr 19, 2013

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page