Linda Pulickal
Linda Pulickal

Reputation: 21

Get description of a Wikidata property?

How can we get a human readable property description of a Wikidata property (e.g.: P31) using pywikibot?

Upvotes: 1

Views: 1540

Answers (1)

leo
leo

Reputation: 8520

You can use action=wbgetentities for properties, just like you would for a normal item.

To get all human readable descriptions for P31:

https://www.wikidata.org/w/api.php?action=wbgetentities&ids=P31

And to limit you results to one language (English):

https://www.wikidata.org/w/api.php?action=wbgetentities&ids=P31&languages=en

Using pywikibot just for that task seems like a bit of overkill (pywikibot is a framework for building bots that do mass editing and the like, primarily on Wikipedia). I'm not sure it's even possible.
There are other, more lightweight frameworks, like wikitools. With wikitools, you would do something like this:

from wikitools import Wiki, APIRequest

pid = "P31"
endpoint = "http://commons.wikimedia.org/w/api.php"
username = "XXX"
password = "XXX"

site = Wiki(endpoint, username, password)
params = {'action':'wbgetentities', 'ids': pid}
request = APIRequest(site, params)
result = request.query()
print result["entities"][pid]["descriptions"]

Upvotes: 1

Related Questions