wikidata.client
— Client session¶
-
wikidata.client.
WIKIDATA_BASE_URL
= 'https://www.wikidata.org/'¶ (
str
) The defaultbase_url
ofClient
constructor.Changed in version 0.3.0: As the meaning of
Client
constructor’sbase_url
parameter, it now became tohttps://www.wikidata.org/
fromhttps://www.wikidata.org/wiki/
(which contained the trailing pathwiki/
).
-
class
wikidata.client.
Client
¶ Wikidata client session.
Parameters: - base_url (
str
) – The base url of the Wikidata.WIKIDATA_BASE_URL
is used by default. - opener (
urllib.request.OpenerDirector
) – The opener forurllib.request
. If omitted orNone
the default opener is used. - entity_type_guess (
bool
) – Whether to guesstype
ofEntity
from itsid
for less HTTP requests.True
by default. - cache_poliy – A caching policy for API calls. No cache
(
NullCachePolicy
) by default.
New in version 0.5.0: The
cache_policy
option.Changed in version 0.3.0: The meaning of
base_url
parameter 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_guess
option.-
cache_policy
= <wikidata.cache.NullCachePolicy object>¶ (
CachePolicy
) A caching policy for API calls.New in version 0.5.0.
-
datavalue_decoder
= None¶ (
Union
[Decoder
,Callable
[[Client
,str
,Mapping
[str
,object
]],object
]]) The function to decode the given datavalue. It’s typically an instance ofDecoder
or its subclass.
-
decode_datavalue
(datatype: str, datavalue: typing.Mapping[str, object]) → object¶ Decode the given
datavalue
using the configureddatavalue_decoder
.New in version 0.3.0.
-
entity_type_guess
= True¶ (
bool
) Whether to guesstype
ofEntity
from itsid
for less HTTP requests.New in version 0.2.0.
-
get
(entity_id: <function NewType.<locals>.new_type at 0x7f692999d6a8>, 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
load
option.
-
guess_entity_type
(entity_id: <function NewType.<locals>.new_type at 0x7f692999d6a8>) → typing.Union[wikidata.entity.EntityType, NoneType]¶ Guess
EntityType
from the givenEntityId
. It could returnNone
when it fails to guess.Note
It always fails to guess when
entity_type_guess
is configued toFalse
.Returns: The guessed EntityId
, orNone
if it fails to guess.Return type: Optional
[EntityType
]New in version 0.2.0.
- base_url (