SPARQL Endpoint interface to Python

This is a wrapper around a SPARQL service. It helps in creating the query URI and, possibly, convert the result into a more manageable format. The package is licensed under W3C license, and it can be downloaded in .zip and .tar.gz formats from SourceForge (also from Debian).

Download SPARQL Endpoint interface to Python The following packages are used:

These packages are imported in a lazy fashion, ie, only when needed. Ie, if the user never intends to use the JSON format, the simplejson package is not imported and the user does not have to install it.

Developers involved:

Here you have an example of how to use the library in your python program:

from SPARQLWrapper import SPARQLWrapper, JSON

sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery("""
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    SELECT ?label
    WHERE { <http://dbpedia.org/resource/Asturias> rdfs:label ?label }
""")
sparql.setReturnFormat(JSON)
results = sparql.query().convert()

for result in results["results"]["bindings"]:
    print result["label"]["value"]

Warning: from version 1.1.0 the package name has changed, now it is SPARQLWrapper; so you will need to update your programs in order to be compatible with latest versions of the library. You can also read online documentation for more information, or contact us in the development mailing list (archives are public).

SPARQL