wikidata.client — Client session¶
-
wikidata.client.WIKIDATA_BASE_URL= 'https://www.wikidata.org/'¶ (
str) The defaultbase_urlofClientconstructor.Changed in version 0.3.0: As the meaning of
Clientconstructor’sbase_urlparameter, it now became tohttps://www.wikidata.org/fromhttps://www.wikidata.org/wiki/(which contained the trailing pathwiki/).
-
class
wikidata.client.Client(base_url: str='https://www.wikidata.org/', opener: typing.Union=None, datavalue_decoder: typing.Union=None, entity_type_guess: bool=True, repr_string: typing.Union=None) → None¶ Wikidata client session.
Parameters: - base_url (
str) – The base url of the Wikidata.WIKIDATA_BASE_URLis used by default. - opener (
urllib.request.OpenerDirector) – The opener forurllib.request. If omitted orNonethe default opener is used. - entity_type_guess (
bool) – Whether to guesstypeofEntityfrom itsidfor less HTTP requests.Trueby default.
Changed in version 0.3.0: The meaning of
base_urlparameter changed. It originally meanthttps://www.wikidata.org/wiki/which contained the trailing pathwiki/, but now it means onlyhttps://www.wikidata.org/.New in version 0.2.0: The
entity_type_guessoption.-
datavalue_decoder= None¶ (
Union[Decoder,Callable[[Client,str,Mapping[str,object]],object]]) The function to decode the given datavalue. It’s typically an instance ofDecoderor its subclass.
-
decode_datavalue(datatype: str, datavalue: typing.Mapping) → object¶ Decode the given
datavalueusing the configureddatavalue_decoder.New in version 0.3.0.
-
entity_type_guess= True¶ (
bool) Whether to guesstypeofEntityfrom itsidfor less HTTP requests.New in version 0.2.0.
-
get(entity_id: <function NewType.<locals>.new_type at 0x7fc400288488>, load: bool=False) → wikidata.entity.Entity¶ Get a Wikidata entity by its
EntityId.Parameters: Returns: The found entity.
Return type: New in version 0.3.0: The
loadoption.
-
guess_entity_type(entity_id: <function NewType.<locals>.new_type at 0x7fc400288488>) → typing.Union¶ Guess
EntityTypefrom the givenEntityId. It could returnNonewhen it fails to guess.Note
It always fails to guess when
entity_type_guessis configued toFalse.Returns: The guessed EntityId, orNoneif it fails to guess.Return type: Optional[EntityType]New in version 0.2.0.
- base_url (