Skip to content

Instantly share code, notes, and snippets.

@asanchez75
Created May 30, 2021 14:53
Show Gist options
  • Save asanchez75/ed152515451b6cb34f6ba3e816eca471 to your computer and use it in GitHub Desktop.
Save asanchez75/ed152515451b6cb34f6ba3e816eca471 to your computer and use it in GitHub Desktop.
from SPARQLWrapper import SPARQLWrapper, POST, BASIC, DIGEST, TURTLE, N3, XML, RDFXML
from rdflib import Graph
sparql = SPARQLWrapper("http://localhost:7200/repositories/myrepo")
sparql.setHTTPAuth(BASIC)
sparql.setCredentials("admin", "admin")
sparql.setMethod(POST)
sparql.setQuery("""
construct {?s ?p ?o}
where {
?s ?p ?o.
}
limit 1000
""")
sparql.setReturnFormat(TURTLE)
results = sparql.query().convert()
g = Graph()
g.parse(data=results, format="turtle")
file = open("output.n3", "wb")
print(g.serialize(destination=file, format='turtle'))
file.flush()
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment