SPARQL Slurper for rdflib
raw JSON → 0.5.1 verified Mon Apr 27 auth: no python
SPARQL Slurper is a Python library that provides an easy way to execute SPARQL queries and iterate over results using rdflib. Version 0.5.1 is the latest stable release, with a maintenance-focused release cadence. It supports Python >=3.7.4.
pip install sparqlslurper Common errors
error ImportError: cannot import name 'SlurpyGraph' from 'sparqlslurper' ↓
cause Installed version is too old (pre-0.5.0) or package name mismatch.
fix
Upgrade sparqlslurper: pip install --upgrade sparqlslurper. Correct import: from sparqlslurper import SlurpyGraph.
error AttributeError: 'NoneType' object has no attribute 's' ↓
cause SPARQL query returned no results; .s attribute is accessed on None row.
fix
Check if query returns results: for row in results: ... or handle with if results:.
error sparqlslurper.SPARQLQueryError: (sparqlslurper) Query error: ... ↓
cause Invalid SPARQL syntax or endpoint issues.
fix
Verify SPARQL syntax with an online validator or endpoint URL. Ensure prefixes are declared.
Warnings
gotcha SlurpyGraph consumes all query results eagerly; large result sets may cause memory issues. ↓
fix Use SPARQLWrapper or rdflib's query() directly for streaming if memory is a concern.
gotcha Query results are returned as namedtuple-like objects; field names depend on SPARQL variable names. ↓
fix Always verify variable names in SELECT clause (e.g., row.s, row.p). Use row.asdict() for dict access.
deprecated The 'sparqlslurper' package has not seen updates since 2021; consider alternatives like rdflib's query directly. ↓
fix Use rdflib's Graph.query() or SPARQLWrapper for active development.
Imports
- SlurpyGraph wrong
from sparqlslurper import SlurperGraphcorrectfrom sparqlslurper import SlurpyGraph
Quickstart
from sparqlslurper import SlurpyGraph
from rdflib import Graph
g = Graph()
g.parse('https://example.org/data.ttl', format='turtle')
slurper = SlurpyGraph(g)
for row in slurper.query('SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10'):
print(row.s, row.p, row.o)