SPARQL/Wikidata Query Service

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Wikimedia runs the public service instance of WDQS (Wikidata Query Service), which is available for use at

GUI[edit | edit source]

The GUI at the home page of 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

Default views[edit | edit source]

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 linkTo column

SPARQL endpoint[edit | edit source]

SPARQL queries can be submitted directly to the SPARQL endpoint with a GET request to POST requests can be sent to 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.

Supported formats[edit | edit source]

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
JSON Accept: application/sparql-results+json format=json JSON result format, as in:
TSV Accept: text/tab-separated-values As specified in
CSV Accept: text/csv As specified in
Binary RDF Accept: application/x-binary-rdf-results-table

Query timeout[edit | edit source]

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 your query does not execute in the allowed time, try to optimize it, or reduce the amount of data it returns.

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[edit | edit source]

See SPARQL/Wikidata Query Service - Introduction

References[edit | edit source]

Other SPARQL Endpoints[edit | edit source]

See for a list of other SPARQL Endpoints.