qwikidata.linked_data_interface module

Module for Wikidata linked data interface endpoints.

exception InvalidEntityId[source]

Bases: Exception

exception LdiResponseNotOk[source]

Bases: Exception

get_entity_dict_from_api(entity_id, base_url='https://www.wikidata.org/wiki/Special:EntityData')[source]

Get a dictionary representing a wikidata entity from the linked data interface API.

https://www.wikidata.org/wiki/Wikidata:Data_access#Linked_Data_interface

Parameters
  • entity_id (Union[NewType()(ItemId, str), NewType()(PropertyId, str), NewType()(LexemeId, str)]) – A Wikidata entity id beginning with “Q”, “P”, or “L” (e.g. “Q42”)

  • base_url (str) – The linked data interface URL to use

Examples

Get the entity dictionary for item Q42,

>>> entity_dict = get_entity_dict_from_api('Q42')
>>> pprint(entity_dict, indent=4, depth=1)
{   'aliases': {...},
    'claims': {...},
    'descriptions': {...},
    'id': 'Q42',
    'labels': {...},
    'lastrevid': 716282445,
    'modified': '2018-07-27T08:03:25Z',
    'ns': 0,
    'pageid': 138,
    'sitelinks': {...},
    'title': 'Q42',
    'type': 'item'}}}
Return type

Union[ItemDict, PropertyDict, LexemeDict]