Fork me on GitHub

RDFLib SPARQL Endpoint interface to Python (1.6.2)

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 GitHub, also from PyPi or from Debian, and eventually from SourceForge where was previously hosted.

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. By the way, you can choose the json module to use using jsonlayer module.

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"])

You can also read online documentation for more information, or contact us at the rdflib-dev; the archives from the old mailing list are still available. And please, report any issue to github.

SPARQL