Wikidata Query API

Run a SPARQL query against Wikidata and get each result row back as a flat record, one key per selected variable, with labels and links ready to use. Build custom lists such as every university in a country.

$0.50 per 1,000 records

You pay only for the records you get. Zero records cost zero. 10,000 free records of this API to start (5,000 at the base price of $1 per 1,000), no card.

Try it
Ready-made, maintained by usRecords, 4 fieldsv1.0

Data from query.wikidata.org/sparql

Get this data

Try it here with a few records, download the sample, fill a Google Sheet, or call it from your own code.

Try it

Query
SPARQL SELECT query text.
Example: SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q3918; wdt:P17 wd:Q16. SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } LIMIT 10

Run it on this page, or call it from your code with the endpoint in the developer section. A free key covers 10,000 records of this API, no card. Create a free key

For developers: the API and MCPThe endpoint, code in curl, JavaScript and Python, every input, and files for your tools
Endpoint
POSThttps://pullrow.dev/v1/apis/wikidata-query/run
  • Small runs answer in the same request; longer ones answer 202 with a run to poll.
  • fields returns only the fields you name. The examples send the ones picked on this page.
  • Idempotency-Key is optional. A retry with it is never charged twice.
  • You pay for records returned. Zero records cost zero.

Every run option, explained

Calling it needs a key
10,000 free records of this API to start. No card.
curl
curl -X POST "https://pullrow.dev/v1/apis/wikidata-query/run" \
  -H "Authorization: Bearer $PULLROW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "input": {
    "query": "SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q3918; wdt:P17 wd:Q16. SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". } } LIMIT 10"
  },
  "max_items": 50
}'

Inputs

Send them as input in the request body. Leave one out to use its default.

querytextrequired
SPARQL SELECT query text.
example: SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q3918; wdt:P17 wd:Q16. SERVICE wikibase:label { bd:serviceParam…

What's in each record

4 fields: 3 here, 1 technical one under Technical details.

Basics

  • Row

    Position of the row in the result, starting at 1.

    Example 1

  • Values

    The row's columns: one key per selected variable, plus <variable>_id for entities.

    Example Item: http://www.wikidata.org/entity/Q631296 · Item ID: Q631296 · Inception: 1946-01-01

  • Columns

    Names of the variables in values, in the order the query selects them.

    Example item, inception

Technical detailsField names and types for developers, and the 1 field hidden above

Hidden by default

This field comes with each record too. It is an internal code, a note about how the record was read or a copy of what was searched for, so the lists above leave it out.

  • Entity IDs entity_idsWikidata ids (such as Q123) of the entities found in the row.

Field names and types

The names your code reads in each record. "Filled" counts how many of the 3 sample records carry the field.

Field nameTypeShown on this page asFilled
rownumberRow3 of 3
valuesgroup of valuesValues3 of 3
columnslistColumns3 of 3
entity_idslistEntity IDs (hidden)3 of 3

How it reads the site

Runs on a reader we built and maintain by hand for this site.

Sample records

Sample records
RecordRowValuesColumns
11Item: http://www.wikidata.org/entity/Q631296 · Item ID: Q631296 · Inception: 1946-01-01item, inception, itemlabel
22Item: http://www.wikidata.org/entity/Q337382 · Item ID: Q337382 · Inception: 1838-01-01item, inception, itemlabel
33Item: http://www.wikidata.org/entity/Q472167 · Item ID: Q472167 · Inception: 1967-01-01item, inception, itemlabel

Sample records from the example output this API publishes. Email addresses and phone numbers in them are masked. Hover over a column name to see the field name your code reads.

Reliability

Counted from real runs. Our own health checks are left out. A run succeeded when it finished and the site neither blocked it nor broke it.

Incidents and repairs

How it is kept working What a repair can't do

A ready-made API, maintained by us. It is not part of the daily check or the automatic rebuild yet.

  • You pay only for records returned. A run that returns none costs nothing.
Known limits
  • You write the SPARQL query; each selected variable becomes a key in the record (lower case), so a bad query returns an input message instead of rows. Include SERVICE wikibase:label to get readable names.
  • Wikidata stops any query that runs longer than 60 seconds, and very heavy queries may be refused: narrow them with filters and a LIMIT.
  • If the query has no LIMIT, one is added from max_items; results come in the source's own order unless the query sorts them.
  • Variables a row leaves unbound are null. Entity values are returned as full links in the variable and their id in <variable>_id.
  • Wikidata data is released CC0. The service asks for modest use and an identifying client; runs send one request at a time.

Version history

A run uses the live version unless the request names another one with version.