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.
# This example includes error handling but it is not necessary here. The user
# may catch the error elsewhere such as in the main function.
try:
response = wrapper.query(query)
except WikidataSPARQLWrapperError as err:
# Handle the error here.
# Get the bindings directly. The remarks about error handling from above apply
# here too.
try:
bindings = wrapper.query_bindings(query)
except WikidataSPARQLWrapperError as err:
# Handle the error here.
# Do something with the bindings.
for binding in bindings:
print(binding["itemLabel"]["value"])
Metadata
Release files for wikidata-sparqlwrapper 2025.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wikidata_sparqlwrapper-2025.1.tar.gz | 7.4 kB | Without provenance | Details for wikidata_sparqlwrapper-2025.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wikidata_sparqlwrapper-2025.1-py3-none-any.whl | Python 3 | none | any | Details for wikidata_sparqlwrapper-2025.1-py3-none-any.whl |
Total release size: 13.0 kB
Release files / wikidata_sparqlwrapper-2025.1.tar.gz
| Download URL | wikidata_sparqlwrapper-2025.1.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d95f4c65efb511de88dafa74c91bf578eb8803735fbb08fda85c9a6fbc4471d7
|
|
BLAKE2b-256 checksum How to use checksums |
aae117d638c7780054748d0e87ce03e38af1b0a0f10c6c838f2bfebec6d3b1e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.1
|
Release files / wikidata_sparqlwrapper-2025.1-py3-none-any.whl
| Download URL | wikidata_sparqlwrapper-2025.1-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2619f5a51ba48bd57de9184d925807db073ee0af0a5aee9722205a0f60f950eb
|
|
BLAKE2b-256 checksum How to use checksums |
b75bb3b0b38cb26a3fdbc56dc3448966848fc6cfc6eb42e20e867589398f94bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.1
|
Security for wikidata-sparqlwrapper 2025.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.