Wrapper around that Wikidata SPARQL endpoint that respects the Wikidata usage policy.
Project description
title: README author: Jan-Michael Rye
Synopsis
A light wrapper around SPARQLWrapper for Wikidata's SPARQL query service. The wrapper attempts to follow Wikidata's usage policy regarding user-agent strings and query frequency.
The wrapper also wraps expected exceptions in a custom exception class to facilitate error handling.
Links
GitLab
Other Repositories
Usage
from wikidata_sparqlwrapper import (
WikidataSPARQLWrapper,
WikidataSPARQLWrapperError,
construct_user_agent_string,
)
# Construct a user-agent string that uniquely identifies your code and which
# includes a contact email address.
agent = construct_user_agent_string(name="MyApp", email="my_email@example.com")
# Instantiate the Wikidata SPARQL wrapper.
wrapper = WikidataSPARQLWrapper(user_agent=agent)
# Construct a SPARQL query.
query = """\
SELECT ?item ?itemLabel
WHERE
{
?item wdt:P31 wd:Q146.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
"""
# Get the SPARQLWrapper query object directly. The format will be set to JSON.
response = wrapper.query(query)
# Get the bindings directly.
bindings = wrapper.query_bindings(query)
# Do something with the bindings.
for binding in bindings:
print(binding["itemLabel"]["value"])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file wikidata_sparqlwrapper-2024.2.tar.gz
.
File metadata
- Download URL: wikidata_sparqlwrapper-2024.2.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cf09ac99ad0524a8778a24f16d9761f3c7a3cb9503735337ee2e2b7131fbc07 |
|
MD5 | bef847374c07ee60f2dad5357c24f1b5 |
|
BLAKE2b-256 | bae1179c55e78f5bd7513b1242f6ac260aaefc185645d84936339e7e77b80c89 |
File details
Details for the file wikidata_sparqlwrapper-2024.2-py3-none-any.whl
.
File metadata
- Download URL: wikidata_sparqlwrapper-2024.2-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fb89b0abad79a386d4ac0a8c12956751f08645a6d4617ffd1fac7e95a0a9b76 |
|
MD5 | 84f67cea49d0236546e1bad556fcd9e9 |
|
BLAKE2b-256 | b884cbd034163e96c4586beb51f5c43591b9410da36fff88b63dd5cb520c6404 |