Entities
client.entities wraps the wbgetentities module of the MediaWiki Action API. It returns one entity, a bounded batch, or an unbounded id list, typed as Entity.
wbgetentities has no search route, so the inherited search entry points raise ConfigurationError before any request: search(), iterate(), collect(), first(), and count(). Search text belongs to client.search, id lists to iterate_ids().
One entity
entity = await client.entities.get("Q42")
entity = await client.entities.get("https://www.wikidata.org/wiki/Q42") # same
The id accepts Q, P, and L ids in any letter case, the wiki URL form, and the entity URL form. The prefix letter is required: a bare number such as "42" raises ConfigurationError because the entity type would be guessed, and M (MediaInfo) ids are rejected. Unknown ids raise NotFoundError.
Pass entity parts with select= (mapped to the API's props parameter) and the remaining parameters through params:
entity = await client.entities.get(
"Q42",
select=["labels", "descriptions"],
params={"languages": ["en", "nl"], "sitefilter": ["enwiki"], "redirects": "no"},
)
redirects accepts "yes" and "no" (default "yes"). With "no", a redirect id answers as a stub entity with info only.
Batches
batch_get() chunks ids at the API's limit of 50 ids per request and returns a dict keyed by the normalized id. An id that the API answers with a missing stub, such as a deleted item, is absent from the dict. An id that makes the API reject the whole request (no-such-entity, for example an item number above the highest one) raises NotFoundError; use iterate_ids(on_error="skip") to drop such ids and keep the rest.
With redirects=yes (the default), a redirect id answers with the entity of its target: the API keys the entities member by the target and reports the mapping in its redirects member. The client reads that member, so the redirected entity stays in the result under the id you asked for (its id attribute carries the target id).
batch = await client.entities.batch_get(["Q42", "P31", "L1"], select=["labels"])
batch_get() inherits the framework's concurrency bound, deduplication, and on_error="skip" failure handling.
Iterating many ids
iterate_ids() walks an unbounded id list in order, 50 ids per request:
async for entity in client.entities.iterate_ids(ids, props=["claims"]):
...
Ids are normalized and deduplicated first. An unknown id raises NotFoundError. With on_error="skip" the client drops the id, repeats the request without it, and records the id in failures with its NotFoundError:
failures = []
async for entity in client.entities.iterate_ids(
ids, on_error="skip", failures=failures
):
...
on_error accepts only "raise" and "skip"; other values raise ConfigurationError before any request. Redirect ids yield the entity of their target.
Checking that an id exists
exists() fetches the entity through get() and returns False when the API rejects the id or answers with a missing stub, because wbgetentities has no HEAD route:
if await client.entities.exists("Q42"):
...
EntityData: the full entity per format
client.entity_data reads wiki/Special:EntityData/{id}.{format}, which serves the full entity in one serialization without the 50-id limit of wbgetentities:
result = await client.entity_data.get("Q42") # json
print(result.entity.id, result.entity.claims)
ttl = await client.entity_data.get("Q42", format="ttl")
print(ttl.document.content_type, len(ttl.document.text))
old = await client.entity_data.get("Q42", revision=2575435918) # an old revision
get() returns an EntityDataResult. For format="json" the entity field carries the parsed Entity (the payload is the same shape as wbgetentities). For jsonld, rdf, nt, ttl, and n3 the document field carries an EntityDataDocument with the raw text and the answered content_type. Other suffixes answer 415, so format is validated client-side. revision= serves an old revision id; an unknown revision answers 404. An invalid id is rejected client-side. A redirect id answers with the entity of its target: the client resolves it through the payload's redirects member, and result.id stays the id you asked for while result.entity.id carries the target id.
negotiate() walks the content-negotiation route for callers who want it: /entity/{id} on the configured host (default https://www.wikidata.org) answers 303 to Special:EntityData based on the Accept header, and the client follows the redirect:
document = await client.entity_data.negotiate("Q42", accept="text/turtle")
Models
Entity carries type, id, labels, descriptions, aliases, claims, sitelinks, datatype (properties), and the page metadata (pageid, lastrevid, modified). Claim carries mainsnak, rank, qualifiers, and references; Snak.datavalue keeps the value untyped (DataValue.value) so every Wikidata value shape survives. Sitelink carries site, title, badges, and url when sitelinks/urls was requested. Unknown fields are kept (extra="allow"), so lexeme payloads survive validation.