> ## Documentation Index
> Fetch the complete documentation index at: https://docs.webrouter.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Wikidata

> Wikimedia's open knowledge base of structured facts: look up items and properties by label, read an item's labels, statements and sitelinks, and run SPARQL queries over the whole graph.

![](https://mintcdn.com/webrouter/8QP9EZc8V07Kl-0I/logo/data-apis/wikidata.webp?fit=max\&auto=format\&n=8QP9EZc8V07Kl-0I\&q=85\&s=85a516a25fa8c6d17ce3b33fd5133e55)

[Web Catalog · Science](https://docs.webrouter.net/data-apis.md?category=science)

No key needed

Endpoints

10

Auth

None

[Vendor docs](https://www.wikidata.org/wiki/Wikidata:REST_API)

## Setup

| Variable | | What it is |
| - | - | - |
| `WIKIDATA_USER_AGENT` | optional | A descriptive User-Agent with contact details, e.g. 'MyAgent/1.0 ([you@example.com](mailto:you@example.com))'; Wikimedia blocks clients without one, so set your own for regular use. Default `WebRouter (+https://github.com/Nimbleway/webrouter)`. |

Put them in your environment or `.env`; [Data APIs](https://docs.webrouter.net/vendors.md) 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

GET

Search items by label

Items whose label or alias matches a term in one language, with their ids and descriptions.

[Open](#wikidata-items-search)

GET

Suggest items by label prefix

Items whose label or alias starts with the typed prefix, for autocomplete.

[Open](#wikidata-items-suggest)

GET

Search properties by label

Properties (P-ids) whose label or alias matches a term, to find the property a statement or SPARQL query needs.

[Open](#wikidata-properties-search)

GET

Get an item

One item's labels, descriptions and aliases in every language, its statements and its sitelinks.

[Open](#wikidata-items-get)

GET

Get an item's statements

The item's statements (property, value, qualifiers, references), optionally for one property only.

[Open](#wikidata-items-statements)

GET

Get an item's label in one language, with fallback

The item's label in a language, falling back to a related language when it has none.

[Open](#wikidata-items-label)

GET

Get an item's sitelinks

The Wikipedia and other Wikimedia pages about the item, by site id (enwiki, dewiki...).

[Open](#wikidata-items-sitelinks)

GET

Get a property

One property's data type, labels, descriptions, aliases and statements.

[Open](#wikidata-properties-get)

GET

Run a SPARQL query

Results of a SPARQL query over the whole Wikidata graph (lists, joins, counts across items).

[Open](#wikidata-sparql-query)

POST

Run a long SPARQL query over POST

The same query service as sparql.query, for queries too long for a URL.

[Open](#wikidata-sparql-query-post)

### Search items by label

GET

`/wikibase/v1/search/items`

`wikidata.items.search`

Items whose label or alias matches a term in one language, with their ids and descriptions.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`q` required</td><td>string</td><td>query</td><td>Term to match against labels and aliases. Example `Douglas Adams`</td></tr>
    <tr><td>`language` required</td><td>string</td><td>query</td><td>Language code to search in. Example `en`</td></tr>

    <tr>
      <td>
        `limit`
      </td>

      <td>
        integer
      </td>

      <td>
        query
      </td>

      <td>
        Maximum results.
      </td>
    </tr>

    <tr>
      <td>
        `offset`
      </td>

      <td>
        integer
      </td>

      <td>
        query
      </td>

      <td>
        Index of the first result.
      </td>
    </tr>
  </tbody>
</table>

[Vendor docs](https://doc.wikimedia.org/Wikibase/master/js/rest-api/)

```python Python theme={null}
router.call_data_api("wikidata.items.search", {'q': 'Douglas Adams', 'language': 'en'})
```

```text MCP theme={null}
call_data_api(endpoint="wikidata.items.search", params={"q": "Douglas Adams", "language": "en"})
```

### Suggest items by label prefix

GET

`/wikibase/v1/suggest/items`

`wikidata.items.suggest`

Items whose label or alias starts with the typed prefix, for autocomplete.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`q` required</td><td>string</td><td>query</td><td>Prefix to match. Example `Douglas Ad`</td></tr>
    <tr><td>`language` required</td><td>string</td><td>query</td><td>Language code to search in. Example `en`</td></tr>

    <tr>
      <td>
        `limit`
      </td>

      <td>
        integer
      </td>

      <td>
        query
      </td>

      <td>
        Maximum results, max 50.
      </td>
    </tr>

    <tr>
      <td>
        `offset`
      </td>

      <td>
        integer
      </td>

      <td>
        query
      </td>

      <td>
        Index of the first result.
      </td>
    </tr>
  </tbody>
</table>

[Vendor docs](https://doc.wikimedia.org/Wikibase/master/js/rest-api/)

```python Python theme={null}
router.call_data_api("wikidata.items.suggest", {'q': 'Douglas Ad', 'language': 'en'})
```

```text MCP theme={null}
call_data_api(endpoint="wikidata.items.suggest", params={"q": "Douglas Ad", "language": "en"})
```

### Search properties by label

GET

`/wikibase/v1/search/properties`

`wikidata.properties.search`

Properties (P-ids) whose label or alias matches a term, to find the property a statement or SPARQL query needs.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`q` required</td><td>string</td><td>query</td><td>Term to match against labels and aliases. Example `date of birth`</td></tr>
    <tr><td>`language` required</td><td>string</td><td>query</td><td>Language code to search in. Example `en`</td></tr>

    <tr>
      <td>
        `limit`
      </td>

      <td>
        integer
      </td>

      <td>
        query
      </td>

      <td>
        Maximum results.
      </td>
    </tr>

    <tr>
      <td>
        `offset`
      </td>

      <td>
        integer
      </td>

      <td>
        query
      </td>

      <td>
        Index of the first result.
      </td>
    </tr>
  </tbody>
</table>

[Vendor docs](https://doc.wikimedia.org/Wikibase/master/js/rest-api/)

```python Python theme={null}
router.call_data_api("wikidata.properties.search", {'q': 'date of birth', 'language': 'en'})
```

```text MCP theme={null}
call_data_api(endpoint="wikidata.properties.search", params={"q": "date of birth", "language": "en"})
```

### Get an item

GET

`/wikibase/v1/entities/items/{item_id}`

`wikidata.items.get`

One item's labels, descriptions and aliases in every language, its statements and its sitelinks.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`item_id` required</td><td>string</td><td>path</td><td>Item id. Example `Q42`</td></tr>

    <tr>
      <td>
        `_fields`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td>
        Comma-separated parts to return: type, labels, descriptions, aliases, statements, sitelinks.
      </td>
    </tr>
  </tbody>
</table>

[Vendor docs](https://doc.wikimedia.org/Wikibase/master/js/rest-api/)

```python Python theme={null}
router.call_data_api("wikidata.items.get", {'item_id': 'Q42'})
```

```text MCP theme={null}
call_data_api(endpoint="wikidata.items.get", params={"item_id": "Q42"})
```

> [!NOTE]
>
> * 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

GET

`/wikibase/v1/entities/items/{item_id}/statements`

`wikidata.items.statements`

The item's statements (property, value, qualifiers, references), optionally for one property only.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`item_id` required</td><td>string</td><td>path</td><td>Item id. Example `Q42`</td></tr>
    <tr><td>`property`</td><td>string</td><td>query</td><td>One property id to keep, e.g. P569. Example `P569`</td></tr>
  </tbody>
</table>

[Vendor docs](https://doc.wikimedia.org/Wikibase/master/js/rest-api/)

```python Python theme={null}
router.call_data_api("wikidata.items.statements", {'item_id': 'Q42', 'property': 'P569'})
```

```text MCP theme={null}
call_data_api(endpoint="wikidata.items.statements", params={"item_id": "Q42", "property": "P569"})
```

> [!NOTE]
>
> * 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

`/wikibase/v1/entities/items/{item_id}/labels_with_language_fallback/{language_code}`

`wikidata.items.label`

The item's label in a language, falling back to a related language when it has none.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`item_id` required</td><td>string</td><td>path</td><td>Item id. Example `Q42`</td></tr>
    <tr><td>`language_code` required</td><td>string</td><td>path</td><td>Language code. Example `en`</td></tr>
  </tbody>
</table>

[Vendor docs](https://doc.wikimedia.org/Wikibase/master/js/rest-api/)

```python Python theme={null}
router.call_data_api("wikidata.items.label", {'item_id': 'Q42', 'language_code': 'en'})
```

```text MCP theme={null}
call_data_api(endpoint="wikidata.items.label", params={"item_id": "Q42", "language_code": "en"})
```

### Get an item's sitelinks

GET

`/wikibase/v1/entities/items/{item_id}/sitelinks`

`wikidata.items.sitelinks`

The Wikipedia and other Wikimedia pages about the item, by site id (enwiki, dewiki...).

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`item_id` required</td><td>string</td><td>path</td><td>Item id. Example `Q42`</td></tr>
  </tbody>
</table>

[Vendor docs](https://doc.wikimedia.org/Wikibase/master/js/rest-api/)

```python Python theme={null}
router.call_data_api("wikidata.items.sitelinks", {'item_id': 'Q42'})
```

```text MCP theme={null}
call_data_api(endpoint="wikidata.items.sitelinks", params={"item_id": "Q42"})
```

### Get a property

GET

`/wikibase/v1/entities/properties/{property_id}`

`wikidata.properties.get`

One property's data type, labels, descriptions, aliases and statements.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`property_id` required</td><td>string</td><td>path</td><td>Property id. Example `P31`</td></tr>

    <tr>
      <td>
        `_fields`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td>
        Comma-separated parts to return: type, data\_type, labels, descriptions, aliases, statements.
      </td>
    </tr>
  </tbody>
</table>

[Vendor docs](https://doc.wikimedia.org/Wikibase/master/js/rest-api/)

```python Python theme={null}
router.call_data_api("wikidata.properties.get", {'property_id': 'P31'})
```

```text MCP theme={null}
call_data_api(endpoint="wikidata.properties.get", params={"property_id": "P31"})
```

### Run a SPARQL query

GET

`/sparql`

`wikidata.sparql.query`

Results of a SPARQL query over the whole Wikidata graph (lists, joins, counts across items).

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`query` required</td><td>string</td><td>query</td><td>The SPARQL query. Example `SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q146. SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } LIMIT 5`</td></tr>
    <tr><td>`format`</td><td>string</td><td>query</td><td>json for SPARQL JSON results; the default is XML. Example `json`</td></tr>
  </tbody>
</table>

[Vendor docs](https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual)

```python Python theme={null}
router.call_data_api("wikidata.sparql.query", {'query': 'SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q146. SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } LIMIT 5', 'format': 'json'})
```

```text MCP theme={null}
call_data_api(endpoint="wikidata.sparql.query", params={"query": "SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q146. SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". } } LIMIT 5", "format": "json"})
```

> [!NOTE]
>
> * 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

POST

`/sparql`

`wikidata.sparql.query_post`

The same query service as sparql.query, for queries too long for a URL.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `query`

        required
      </td>

      <td>
        string
      </td>

      <td>
        body
      </td>

      <td>
        The SPARQL query, sent as the form field query.
      </td>
    </tr>

    <tr><td>`format`</td><td>string</td><td>query</td><td>json for SPARQL JSON results; the default is XML. Example `json`</td></tr>
  </tbody>
</table>

[Vendor docs](https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual)

> [!NOTE]
>
> * 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.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.