import pywikibot
site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()
item = pywikibot.ItemPage(repo, "Q76")
item_dict = item.get()
clm_dict = item_dict["claims"]
clm_list = clm_dict["P214"]
for clm in clm_list:
    print(clm.toJSON())
{'mainsnak': {'snaktype': 'value', 'property': 'P214', 'datatype': 'external-id', 'datavalue': {'value': '52010985', 'type': 'string'}}, 'type': 'statement', 'id': 'q76$9AF526A1-C489-4E26-93E0-B831DE7EC2AD', 'rank': 'preferred', 'references': [{'snaks': {'P143': [{'snaktype': 'value', 'property': 'P143', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 8447}, 'type': 'wikibase-entityid'}}]}, 'snaks-order': ['P143'], 'hash': 'd4bd87b862b12d99d26e86472d44f26858dee639'}]}
{'mainsnak': {'snaktype': 'value', 'property': 'P214', 'datatype': 'external-id', 'datavalue': {'value': '360145857918723020242', 'type': 'string'}}, 'type': 'statement', 'id': 'Q76$b4f898b5-4c39-f03c-6ec1-c14337ce879c', 'rank': 'preferred'}
for clm in clm_list:
    clm_trgt = clm.getTarget()
    print(clm_trgt)
52010985
360145857918723020242
 
import SPARQLWrapper import JSON from SPARQLWrapper import SPARQLWrapper sparql = SPARQLWrapper("https://query.wikidata.org/sparql") sparql.setQuery(""" SELECT ?person ?personLabel WHERE { ?person wdt:P214 "52010985" SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } """) sparql.setReturnFormat(JSON) results = sparql.query().convert() for result in results["results"]["bindings"]: print(result["personLabel"]["value"]) print(result["person"]["value"])