Wikidata SPARQL API
Read-only SPARQL queries with typed bindings and a row count.
GET /v1/wikipedia/wikidata/query1 credit Failed requests are free
About this endpoint
GET /v1/wikipedia/wikidata/query?sparql=SELECT%20... runs a read-only SPARQL query and returns data.head.vars, data.bindings, data.boolean and data.rowCount. bindings is an array of rows, and each binding value has type, value and, where relevant, datatype and lang.
format only accepts json. sparql is limited to 10,000 characters. The query must be read-only: INSERT, DELETE, LOAD, CLEAR, DROP, CREATE, ADD, MOVE, COPY and WITH are refused. A SELECT returns rows in bindings; an ASK answer returns the result in boolean and leaves bindings empty. empty is true when a SELECT matched no rows.
rowCount always matches the length of bindings. The result is capped at 2,000,000 bytes, so add a LIMIT or narrow the query when it grows. Wikidata applies its own timeout to long queries, so keep queries narrow and select only the variables you need.
Wikidata SPARQL API FAQ
Can I write to Wikidata with this route?
No. Only read-only queries are accepted. Statements that change data, such as INSERT, DELETE, LOAD, CLEAR, DROP, CREATE, ADD, MOVE, COPY and WITH, are refused before the query runs.
How do I read an ASK answer?
An ASK query fills data.boolean with true or false. bindings is empty for an ASK answer, and head.vars lists the variables the service reports.
Why is rowCount useful?
rowCount is the number of rows in bindings, so you can check that a query returned what you expected without counting the array. A SELECT with no matches is found with rowCount 0 and empty true.
How many credits does a SPARQL query cost?
Pricing is documented on the operation in the API registry (shown on this page). Confirm on every response with meta.creditsCharged: that field is the billing source of truth.
Other Wikipedia endpoints
- PageGET /v1/wikipedia/pages/{title}
- Pages by titleGET /v1/wikipedia/pages
- Page contentGET /v1/wikipedia/pages/{title}/content
- RevisionsGET /v1/wikipedia/pages/{title}/revisions
- History statsGET /v1/wikipedia/pages/{title}/history-stats
- BacklinksGET /v1/wikipedia/pages/{title}/backlinks
- LinksGET /v1/wikipedia/pages/{title}/links
- LanguagesGET /v1/wikipedia/pages/{title}/languages