Search for items and properties on Wikidata and retrieve entity details, claims, and external identifiers. Supports both keyword search (Wikidata Action API) and semantic/hybrid search (Wikidata Vector Database), plus direct entity retrieval (Special:EntityData) and structured querying (WDQS SPARQL).
Search and retrieve data from Wikidata, the free knowledge base.
Use the method that matches the task to reduce load and improve accuracy:
Base URL: `https://www.wikidata.org/w/api.php`
Entity JSON (often faster for current state): `https://www.wikidata.org/wiki/Special:EntityData/{ID}.json`
SPARQL endpoint: `https://query.wikidata.org/sparql`
Vector DB API: `https://wd-vectordb.wmcloud.org`
Search for entities by label or alias.
```bash
curl 'https://www.wikidata.org/w/api.php?action=wbsearchentities&search=QUERY&language=en&format=json&type=item&limit=10'
```
Parameters:
Response fields per result:
Retrieve full entity data including claims/identifiers.
```bash
curl 'https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q42&format=json&props=labels|descriptions|aliases|claims'
```
Parameters:
Retrieve claims for specific entity/property.
```bash
curl 'https://www.wikidata.org/w/api.php?action=wbgetclaims&entity=Q42&property=P31&format=json'
```
When you don't know the exact label, or want "things like this" discovery, use the Vector DB.
Item search:
```bash
curl 'https://wd-vectordb.wmcloud.org/item/query/?query=QUERY&lang=all&K=20'
```
Property search:
```bash
curl 'https://wd-vectordb.wmcloud.org/property/query/?query=QUERY&lang=all&K=20&exclude_external_ids=false'
```
Optional parameters:
Response fields:
```bash
curl 'https://www.wikidata.org/wiki/Special:EntityData/Q42.json?flavor=simple'
```
`flavor`:
```bash
curl -G 'https://query.wikidata.org/sparql' --data-urlencode 'query=SELECT * WHERE { wd:Q42 ?p ?o } LIMIT 5' -H 'Accept: application/sparql-results+json'
```
External identifiers are stored as claims with datatype `external-id`. Common identifier properties:
| Property | Name | Example |
| -------- | ---------------------- | ---------------------- |
| P214 | VIAF ID | 75121530 |
| P227 | GND ID | 119033364 |
| P244 | Library of Congress ID | n79023811 |
| P213 | ISNI | 0000 0001 2144 9326 |
| P345 | IMDb ID | nm0001354 |
| P646 | Freebase ID | /m/0282x |
| P349 | NDL ID | 00621256 |
| P268 | BnF ID | 11888092r |
| P269 | IdRef ID | 026927608 |
| P906 | SELIBR ID | 182099 |
| P396 | SBN author ID | IT\\ICCU\\CFIV\\000163 |
To extract identifiers from `wbgetentities` response:
```python
```
Use `scripts/wikidata_api.py` for programmatic access:
```python
from scripts.wikidata_api import WikidataAPI
wd = WikidataAPI()
results = wd.search("Albert Einstein", language="en", limit=5)
entity = wd.get_entity("Q937", props=["labels", "descriptions", "claims"])
identifiers = wd.get_identifiers("Q937")
candidates = wd.vector_search_items("a famous science fiction writer", lang="en", k=5)
raw = wd.execute_sparql("SELECT * WHERE { wd:Q42 ?p ?o } LIMIT 5")
```
```json
{
"searchinfo": {"search": "query"},
"search": [
{
"id": "Q42",
"label": "Douglas Adams",
"description": "English writer and humorist",
"aliases": ["Douglas Noël Adams"],
"url": "//www.wikidata.org/wiki/Q42"
}
]
}
```
```json
{
"entities": {
"Q42": {
"type": "item",
"id": "Q42",
"labels": {"en": {"language": "en", "value": "Douglas Adams"}},
"descriptions": {"en": {"language": "en", "value": "..."}},
"claims": {
"P31": [...], // instance of
"P214": [{"mainsnak": {"datavalue": {"value": "113230702"}}}] // VIAF
}
}
}
}
```
1. **Choose the right access method**: search vs vector search vs entity fetch vs SPARQL
2. **Rate limiting**: add 500ms-1s delay between requests
3. **Batch requests**: use pipe-separated IDs (max 50 per `wbgetentities` call)
4. **Set User-Agent**: include contact info in headers
5. **Handle 429**: respect `Retry-After` and back off
6. **Action API etiquette**: use `maxlag` and request only needed `props`
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/wikidata-search/raw