Site links
Site links connect an item to its article on a Wikimedia site. Wikidata serves them through client.sitelinks (the wbgetentities route, all links of an item at once) and through client.items.sitelink (the REST route, one link). The examples on this page use the client from the first block; later
blocks reuse it.
import asyncio
from bibliofabric.wikidata import WikidataClient
client = WikidataClient()
List the site links of an item
links = await client.sitelinks.get("Q42", sites=["enwiki", "dewiki"], with_urls=True)
print("sites:", sorted(links))
print("enwiki:", links["enwiki"].title, links["enwiki"].url)
print("badges:", links["enwiki"].badges)
sites: ['dewiki', 'enwiki']
enwiki: Douglas Adams https://en.wikipedia.org/wiki/Douglas_Adams
badges: ['Q17437798']
get() returns a SitelinkMap dict keyed by site id. sites= maps to the sitefilter parameter and takes one site id or a sequence; without it, the answer covers every linked site. with_urls=True asks for the sitelinks/urls property, so each Sitelink carries the resolved article url. An item without site links answers {}.
Read one site link through REST
link = await client.items.sitelink("Q42", "enwiki")
print(link.title, link.badges)
Douglas Adams ['Q17437798']
The REST route returns one RestSitelink and carries no URL resolution, only title and badges.
Badges
A badge marks why a link is notable, for example Q17437798 (good article). client.utilities.available_badges() lists every badge id the site accepts; see utility modules.