SPARQL/Wikidata Query Service
Wikimedia runs the public service instance of WDQS (Wikidata Query Service), which is available for use at http://query.wikidata.org/.
The GUI at the home page of http://query.wikidata.org/ allows you to edit and submit SPARQL queries to the query engine. The results are displayed as an HTML table. Note that every query has a unique URL which can be bookmarked for later use. Going to this URL will put the query in the edit window, but will not run it - you still have to click "Execute" for that.
One can also generate a short URL for the query via a URL shortening service by clicking the "Generate short URL" link on the right - this will produce the shortened URL for the current query.
The "Add prefixes" button generates the header containing standard prefixes for SPARQL queries. The full list of prefixes that can be useful is listed in the RDF format documentation. Note that most common prefixes work automatically, since WDQS supports them out of the box.
The GUI also features a simple entity explorer which can be activated by clicking on the "🔍" symbol next to the entity result. Clicking on the entity Q-id itself will take you to the entity page on wikidata.org.
If you run the query in the WDQS GUI, you can choose which view to present by specifying a comment:
#defaultView:viewName at the beginning of the query. Supported views are:
Table- default view, displays the results as a table of values
Map- displays coordinate points if any present in the result
ImageGrid- displays images present in the result as a grid
BubbleChart- displays bubble chart for numbers found in the result
TreeMap- displays hierarchical tree map for numbers found in the result
Timeline- for results having dates, displays timeline placing each row at appropriate time
Dimensions- displays rows as lines between points on the scales representing each column
Graph- displays result as a connected graph, using
SPARQL queries can be submitted directly to the SPARQL endpoint with a GET request to
https://query.wikidata.org/sparql?query=SPARQL (POST and other method requests will be denied with a "403 Forbidden"). 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.
JSON format is standard SPARQL 1.1 Query Results JSON Format.
The following output formats are currently supported by the SPARQL endpoint:
|Format||HTTP Header||Query parameter||Description|
|XML||Accept: application/sparql-results+xml||format=xml||XML result format, is returned by default. As specified in https://www.w3.org/TR/rdf-sparql-XMLres/|
|JSON||Accept: application/sparql-results+json||format=json||JSON result format, as in: https://www.w3.org/TR/sparql11-results-json/|
|TSV||Accept: text/tab-separated-values||As specified in https://www.w3.org/TR/sparql11-results-csv-tsv/|
|CSV||Accept: text/csv||As specified in https://www.w3.org/TR/sparql11-results-csv-tsv/|
|Binary RDF||Accept: application/x-binary-rdf-results-table|
There is a hard query deadline configured which is set to 60 seconds. That is true both for the GUI and the public SPARQL endpoint. If you need to run longer queries, please contact the Discovery team.
Every query will timeout when it takes more time to execute than this configured deadline. You may want to optimize the query or report a problematic query here mw:Wikidata_query_service/Problematic_queries
Introduction to Wikidata Query Service
Other SPARQL Endpoints
See www.w3.org/wiki/SparqlEndpoints for a list of other SPARQL Endpoints.