Instantly share code, notes, and snippets.

@jindrichmynarz /wikidata.py Secret
Last active Sep 11, 2018

Embed
What would you like to do?
SPARQL: It's just HTTP!
#!/usr/bin/env python
import urllib
from rdflib import Graph
def main():
endpoint = "https://query.wikidata.org/sparql"
query = """
CONSTRUCT WHERE {
?s ?p ?o .
}
LIMIT 10
"""
url = endpoint + "?" + urllib.urlencode({"query": query})
g = Graph()
g.parse(url)
print(g.serialize(format = "n3"))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment