How can we get a human readable property description of a Wikidata property (e.g.: P31) using pywikibot?
Asked
Active
Viewed 1,440 times
1
-
See https://www.mediawiki.org/wiki/Manual:Pywikibot/Wikidata for a general intro to using Pywikibot with Wikidata. – Adrian Heine Mar 23 '15 at 18:21
1 Answers
1
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"]

leo
- 8,106
- 7
- 48
- 80