A service that offers the ability to run complex queries on items in Wikidata.
Also, the data used here is from WikiData "dumps", so it can be a few hours old.
For the impatient.
- Places in the U.S. that are named after Francis of Assisi
- All items in the taxonomy of the Komodo dragon
- All animals on Wikidata
- Bridges in Germany
- Bridges across the Danube
- Items with VIAF string "64192849"
- People who were born 1924-1925, and died 2012-1013
- Items 15km around the center of Cambridge, UK
A query URL is always based on:
/api?q=QUERYQUERY is a plain-text string, vaguely similar to an SQL query. It currently offers the following commands:
This finds all items with claims that either have a specific PROPERTY (omitting :ITEM), or that have a claim for a PROPERTY towards a specific ITEM.
Example: claim[138:676555] returns all items that are named after (P138) Francis of Assisi (Q676555).
Multiple such claim statements can be concatenated within  by commas; all items fulfilling any of the statements (union) will be returned.
Note that the item-less form of this query also works for string, time, and coordinate properties.
Alternatively, a nested query (subquery) can be used instead of the item. The resulting items of the subquery are then all used together with the property.
Example: claim[31:(tree)] gives a list of all instances (P31) of subclasses (P279) of bridges Q12280.
Similar to claim this removes all items with claims that either have a specific PROPERTY (omitting :ITEM), or that have a claim for a PROPERTY towards a specific ITEM, from the current result set.
noclaim must be part of an AND statement, and must not be the first element in it; it can only work on an existing item list.
Example: claim[138:676555] AND noclaim[31:515] returns all items that are named after (P138) Francis of Assisi (Q676555) and are not an instance of (P31) city (Q515).
Multiple such claim statements can be concatenated within  by commas; all items fulfilling any of the statements (union) will be removed.
Alternatively, a nested query (subquery) can be used instead of the item. See claim above for details.
This returns all items on a tree of properties (can be separated by commas), following properties recursively from root items.
- The first list (one or multiple ITEM) are the root elements of the tree.
- The second list (one or multiple PROPERTY, can be empty) is the list of properties to follow forward; that is, if root item R has a claim P:I, and P is in the list, the search will branch recursively to item I as well.
An example would be to follow a taxonomy, starting from a species.
- The third list (one or multiple PROPERTY, can be empty, or omitted entirely) is the list of properties to follow in reverse;
that is, if (for a root item R) an item I has a claim P:R, and P is in the list, the search will branch recursively to item I as well.
An example would be to find all places in a country by following the "in administrative unit" trail in reverse, starting form the country.
This finds all items with string value STRING for PROPERTY.
This finds all items with coordinates in PROPERTY (usually 625) that are no more that RADIUS km (accepts fractions, e.g. "2.5") away from LATITUDE,LONGITUDE (decimal degrees, e.g. "52.205,0.119"). Precision is ignored.
This finds all items with times in PROPERTY between BEGIN and END times. Either BEGIN or ,END (with comma!) can be omitted to indicate "any value", but not both. Ranges are inclusive, precision is ignored, calendar is always Gergorian.
Times are given in the format +00000001861-03-17T00:00:00Z, though short versions are allowed, e.g. "1974" or "1974-05"; missing values will be set to 0, even months and days, so "before 1974" becomes "before 1974-00-00T00:00:00Z".
Excessive values are allowed, e.g. "before 1974-05-32" gives all dates before, and including, May 1974.
- link[wiki,wiki,...] / nolink[wiki,wiki,...]
link finds all items with links to any of the stated wikis.
nolink finds all items without links to any of the stated wikis.
Example: link[dewiki] and nolink[frwiki] returns all items that have a link to dewiki but not to frwiki.
- AND / OR
You can join multiple of the above queries into a subset (AND) or union (OR). Use spaces around either to separate them from the queries they connect.
Example: tree[17,131] AND claim[138:676555] returns all items (three in total) that are both
- places in the "reverse tree" of country (P17) or administrative unit (P131) within the U.S.A. (Q30), or areas it subdivides into (P150 of the "forward tree"), and
- named after (P138) Francis of Assisi (Q676555)
- ( / )
You can manually group commands with parentheses. Commands in parentheses will be run first, and their results used in their stead.
- All properties and items are numeric
- Commands are case-insensitive
Adding a "labels" parameter to the URL will return labels for the resulting items. L1, L2, etc. are comma-separated language codes, such as "en" or "de". L1 is the preferred language; if no label in that language exists for an item, L2 will be used, and so on. (Komodo dragon example)
EXPERIMENTAL! Adding a "props" parameter will return the specified properties for the resulting items. P1, P2, etc. are comma-separated property numbers. Using a single "*" instead of a property number list will return all properties of the resulting items, though that can take significantly longer, and generate much more data. If "props" is used together with "labels", labels for the properties and all items in property values ("target items") will be generated as well. (Komodo dragon example)
- Result format is JSON