Wikidata:SPARQL query service
What is SPARQL
SPARQL (pronounced "sparkle") is an RDF query language, that is, a semantic query language for databases. Wikidata provides an SPARQL endpoint including a powerful web GUI since September 2015. With SPARQL, you can extract any kind of data, with a query composed of logical combinations of triples.
- SPARQL query service GUIs are here: https://query.wikidata.org and https://query-scholarly.wikidata.org
- SPARQL Endpoint: https://query.wikidata.org/bigdata/namespace/wdq/sparql?query={SPARQL} (some docs for this API endpoint)
Learning SPARQL

Help for new queries
- Wikidata Query Service help portal
- Wikidata:SPARQL query service/queries
- If you can't adjust the examples to create a new query, you could request the query, try using the query helper tool, or try using the Spinach Wikidata bot to create a new query or adjust an existing one using natural language
- Queries from Wikidata status update weekly summaries
Other materials
- SPARQL in 11 minutes (video, English)
- SPARQL Tutorial at the Apache Jena website (English)
- 2016 SPARQL Workshop presented by the Wikimedia Foundation (English)
- Querying Wikidata with SPARQL for Absolute Beginners, 2-hour video tutorial (English)
- Wikidata:SPARQL tutorial (multiple languages)
- Query optimization
- Query limits
-
{{Item documentation}}
and other generic queries templates
Interfacing
SPARQL queries can be submitted directly to the SPARQL endpoint with GET request to https://query.wikidata.org/bigdata/namespace/wdq/sparql?query={SPARQL}
or the endpoint's alias https://query.wikidata.org/sparql?query={SPARQL}
. The result is returned as XML by default, or as JSON if either the query parameter format=json
or the header Accept: application/sparql-results+json
are provided. See the user manual for more detailed information. RDF data can alternatively be accessed via a Linked Data Fragments interface at https://query.wikidata.org/bigdata/ldf
.
- The R package WikidataQueryServiceR which queries the WDQS SPARQL endpoint and returns
data.frames
. - The R script leprosyInAmerica.r that plots Wikidata content on a world map. (Andra Waagmeester, mailing list discussion)
- An introduction to Observable for Wikidata users
- Python example, how to make a plot of causes of death for U.S. Presidents
- An example of using SPARQLWrapper library to query WDQS in Python: https://people.wikimedia.org/~bearloga/notes/wdqs-python.html
- An example using the Apache Jena command line tools. (This is useful e.g. for very large SPARQL statements with +2000 lines which WDQS UI currently cannot handle properly because of the parsing, or e.g., for scripting a batch of queries to run every week (via cron) and report the results by email)
- Convert WDQ (the previous tool to query Wikidata) queries syntax to SPARQL (by Stas Malyshev)
- Generate plots for results by cutting-and-pasting queries to (Visual) SPARQL query tool. Some examples by User:Pyb: U.S. States by date of creation, Burial counts for Père Lachaise cemetery by year, Dates of birth of 2000 centenarians
Wikimedia SPARQL query services
Human interface | Machine's endpoint | Description |
---|---|---|
https://query.wikidata.org/sparql |
Run SPARQL Queries on the "main" subset upon the Wikidata Wikibase instance. Run, test, download the data as XML, JSON, CSV, or TSV. Has advanced user-friendly features such as: word hovering to see a term's meaning, code optimization, etc. | |
https://query-scholarly.wikidata.org/sparql |
Run SPARQL Queries on the "scholarly" subset upon the Wikidata Wikibase instance (cf. WDQS graph split for more information). Run, test, download the data as XML, JSON, CSV, or TSV. Has advanced user-friendly features such as: word hovering to see a term's meaning, code optimization, etc. | |
https://commons-query.wikimedia.org/sparql |
Run SPARQL Queries upon the Wikimedia Commons Wikibase instance. | |
https://lingualibre.org/bigdata/#query |
Run SPARQL Queries upon the LinguaLibre Wikibase instance. Run, test, download the data as XML, JSON, CSV, or TSV. |
Federated queries
Up-to-date federation documentation is gathered on the page Wikidata:SPARQL_query_service/Federated_queries.
Lists of available endpoints: Report that tests available endpoints for federation. The report is based on this list. And this is the production config.
An older list of available endpoints that is currently not being updated.
Stats
Further resources
- Special:ListDatatypes - covers approximate prefixes and explanation of some values
- Help:Dates - additional notes about dates
- Wikidata:SPARQL query service/Documentation - a hub for documents about the WDQS, organized under the Diátaxis framework
- SPARQL 1.1 W3C Recommendation
- Blazegraph wiki - Blazegraph is the query engine used by the Wikidata SPARQL query service. The wiki provides useful insights.
- Alternative endpoints
- Blazegraph comparison and limitations