API Reference#

Akinator#

class asyncakinator.Akinator(language: Language = Language.ENGLISH, theme: Theme = Theme.CHARACTERS, child_mode: bool = False, session: ClientSession | None = None)#

A class that represents an async Akinator game.

Note

Some attributes will be missing before a game has started. Use Akinator.start() a game before accessing these attributes. Some attributes will be missing until a game has ended. Use Akinator.win() to end a game before accessing these attributes.

Parameters:
  • language (Language) – The language to use when starting the game. If left blank, defaults to Language.ENGLISH.

  • theme (Theme) – The theme to use when starting the game. If left blank, defaults to Theme.CHARACTERS.

  • child_mode (bool) – Whether to use child mode or not. Defaults to False.

question#

The question that Akinator is asking.

Type:

str

progression#

How far in the game you are.

Type:

float

step#

The question you are on, starting from 0.

Type:

int

first_guess#

A dictionary containing the first guess information.

Type:

Guess

guesses#

A list of Guess dictionary of guesses from greatest to least probability.

Type:

list[Guess]

uri#

The uri that is being used.

Type:

str

server#

The server that is being used.

Type:

str

signature#

An int that represents a game’s signature.

Type:

int

uid#

Represents a games Unique ID, used for authentication purposes.

Type:

str

frontaddr#

An IP address in Base64, used for authentication purposes.

Type:

str

timestamp#

A POSIX timestamp that is set when Akinator.start() is called

Type:

int

session#

Represents a game’s session.

Type:

int

Raises:

TypeError – The session is not an aiohttp.ClientSession.

await start(language: Language | None = None, theme: Theme | None = None, child_mode: bool | None = None) str#

Starts a new game. This should be called before any other method.

Parameters:
  • language (Language | None) – The language to use when starting the game. If None, the language specified in the constructor will be used.

  • theme (Theme | None) – The theme to use when starting the game. If None, the theme specified in the constructor will be used.

  • child_mode (bool) – Whether or not to use child mode. If True, the game will be more “child-friendly”. If None, the child mode specified in the constructor will be used.

Returns:

The first question that Akinator is asking.

Return type:

str

await answer(answer: Answer) str#

Answers the current question accessed with Akinator.question, and returns the next question.

Parameter#

answer: Answer

The answer to the current question.

Note

Calling this method with Answer.BACK will call Akinator.back() for you.

raises NoMoreQuestions:

There are no more questions to be asked. Call Akinator.win() to get the results.

raises CanNotGoBack:

The Akinator game is on the first question, so it can’t go back anymore.

raises NotStarted:

Occurs when you try to answer a question before starting the game.

returns:

The next question that Akinator asks.

rtype:

str

await back() str#

Go back to the previous question.

Note

Akinator.answer() will call this method for you if you pass in Answer.BACK. It is recommended that you use that for better experience.

Raises:
  • CanNotGoBack – The Akinator game is on the first question, so it can’t go back anymore.

  • NotStarted – Occurs when you try to answer a question before starting the game.

Returns:

The previous question that Akinator asked.

Return type:

str

await win() Guess#

Get Akinator’s current guesses based on the responses to the questions thus far.

This function will set:

Akinator.first_guess

The first guess that is returned

Akinator.guesses

A list of guesses from greatest to lowest probablity

Note

It is recommended that you call this function when Akinator.progression is above 85.0, because by then, Akinator will most likely narrowed the guesses down to one.

Raises:

NotStarted – Occurs when you try to answer a question before starting the game.

Returns:

The first guess that Akinator has. Also set in Akinator.first_guess.

Return type:

Guess

await end() Guess#

Alias to Akinator.win().

await close() None#

Closes the aiohttp ClientSession.

Caution

If you specified your own ClientSession, this may interrupt what you are doing with the session.

Models#

class asyncakinator.Answer(value)#

Represents the answer to a question.

YES = 0#
NO = 1#
I_DONT_KNOW = 2#
PROBABLY = 3#
PROBABLY_NOT = 4#
BACK = 5#
classmethod from_str(answer: str) Answer#

Allows for the creation of an Answer from a string.

Parameters:

answer (str) –

The answer to convert to Answer.

For Answer.YES, the following are valid:

yes, y, and 0.

For Answer.NO, the following are valid:

no, n, and 1.

For Answer.I_DONT_KNOW, the following are valid:

i dont know, i don't know, idk, and 2.

For Answer.PROBABLY, the following are valid:

probably, p, and 3.

For Answer.PROBABLY_NOT, the following are valid:

probably not, pn, and 4.

For Answer.BACK, the following are valid:

back, b, and 5.

Raises:

InvalidAnswer – The answer you provided is not valid.

Return type:

Answer

class asyncakinator.Language(value)#

Represents the language of the game.

ENGLISH = 'en'#
ARABIC = 'ar'#
CHINESE = 'cn'#
GERMAN = 'de'#
SPANISH = 'es'#
FRENCH = 'fr'#
HEBREW = 'il'#
ITALIAN = 'it'#
JAPANESE = 'jp'#
KOREAN = 'kr'#
DUTCH = 'nl'#
POLISH = 'pl'#
PORTUGUESE = 'pt'#
RUSSIAN = 'ru'#
TURKISH = 'tr'#
INDONESIAN = 'id'#
classmethod from_str(language: str) Language#

Create a Language from a string.

The short form of a language (en for English, fr for French, etc.) is also accepted.

Parameters:

language (str) – The language to convert to Language.

Raises:

InvalidLanguage – The language you provided is not valid.

Return type:

Language

class asyncakinator.Theme(value)#

Determines what server to use when starting a game.

CHARACTERS = 1#
OBJECTS = 2#
ANIMALS = 14#
classmethod from_str(theme: str) Theme#

Create a Theme from a string.

Parameters:

theme (str) –

The theme to convert to Theme.

For Theme.CHARACTERS, the following are valid:

characters, ch, and c.

For Theme.OBJECTS, the following are valid:

objects, obj, and o.

For Theme.ANIMALS, the following are valid:

animals, and a.

Raises:

InvalidTheme – The theme you provided is not valid.

Return type:

Theme

class asyncakinator.Guess(id: int, name: str, probablility: float, description: str, ranking: int, absolute_picture_path: str, _data: _GuessDict | None)#

Class representing a guess.

id#

The ID of the guess.

Type:

int

name#

The name of the guess.

Type:

str

probablility#

The probability that the guess is correct.

Type:

float

description#

The description of the guess.

Type:

str

ranking#

The ranking of the guess.

Type:

int

absolute_picture_path#

A URL to the picture of the guess.

Type:

str

Utils#

MISSING#

akinator.utils.MISSING#

A sentinel value that is used to indicate a missing value with distinction from None.

Exceptions#

class asyncakinator.InputError#

Raised when the user inputs an invalid answer

class asyncakinator.InvalidAnswer#

Raised when the user inputs an invalid answer

class asyncakinator.InvalidLanguage#

Raised when the user inputs an invalid language

class asyncakinator.InvalidTheme#

Raised when the user inputs an invalid theme

class asyncakinator.ConnectionFailure#

Raised if the Akinator API fails to connect for some reason.

class asyncakinator.TimedOut#

Raised if the Akinator session times out

class asyncakinator.NoMoreQuestions#

Raised if the Akinator API runs out of questions to ask. This will happen if “Akinator.step” is at 79

class asyncakinator.ServerDown#

Raised if Akinator’s servers are down for the region you’re running on.

class asyncakinator.TechnicalServerError#

Raised if Akinator’s servers had a technical error.

class asyncakinator.NotStarted#

Raised when the user tries to do something before starting the game.

class asyncakinator.CanNotGoBack#

Raised when the user is on the first question and tries to go back further.