Setup
Put them in your environment or
.env; Data APIs covers the other ways.
Notes
- Keyless for reads. Wikimedia’s User-Agent policy applies to both hosts: a generic or missing User-Agent can be blocked; set WIKIDATA_USER_AGENT with your contact details.
- Ids: items are Q-numbers (Q42), properties P-numbers (P31 instance of, P569 date of birth). Find ids with the search calls, then read the item.
- The REST API is versioned in the path (wikibase/v1); its rate limits follow MediaWiki’s and are not published as numbers.
- SPARQL: 60 seconds of query time per 60 seconds per client (User-Agent plus IP), 5 parallel queries per IP, 30 failing queries per minute, and each query is cut off at 60 seconds. 429 carries Retry-After; ignoring it can get a temporary ban.
Endpoints
Search items by label
Suggest items by label prefix
Search properties by label
Get an item
- A whole item is large (every language); pass _fields or use the labels and statements calls to keep it small.
Get an item’s statements
- Values that are items come back as ids only; read their labels with items.label.
Get an item’s label in one language, with fallback
Get an item’s sitelinks
Get a property
Run a SPARQL query
- Pass format=json, or results come back as XML.
- GET answers are cached; use sparql.query_post only for queries too long for a URL.
Run a long SPARQL query over POST
- A read: POST only carries a long query past URL limits, and the query service is read-only (SPARQL SELECT/ASK/CONSTRUCT/DESCRIBE; it changes nothing).
- POST answers are not cached, so prefer GET when the query fits in a URL.