Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

KankaClient class

Spectre edited this page Jul 25, 2021 · 2 revisions

KankaClient class

This class is the core of pykanka. It should normally be the only class initialized directly by the user.


Initialization:

KankaClient(token: str, campaign: Union[str, int], cache_duration: int)

token: A Kanka API token. This is needed to access user campaigns and can be generated here: https://kanka.io/en/settings/api.

campaign: Either a campaign ID as an integer, or a campaign name as a string.

cache_duration Duration in seconds for requests to be cached. Set to 0 to disable caching.


Methods:

KankaClient.search(name: int, results: int = 1)

name: The term to be searched.

results: Number of results to return. Since the 'search' endpoint doesn't return all entity data, a separate API call is needed for each result, so a low number is desirable.

returns: A list of Entity object matching the search term.


KankaClient.get_entity(entity: int = None)

entity_id: Entity ID as an integer.

returns: An Entity object. If an ID is provided, it requests it from kanka.io, otherwise an empty Entity object is created.


Child objects (example Character)

KankaClient.get_character(character_id: int = None)

character_id: Character ID as an integer, can be found at the end of Character URLSs on kanka.io.

returns: A character object. If an ID is provided, it requests it from kanka.io, otherwise an empty Character object is created.


KankaCLient.all_characters()

returns: A tuple consisting of a generator object that yields Character objects and the total number of characters as an int.

Clone this wiki locally