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. UseAkinator.win()to end a game before accessing these attributes.- Parameters:
language (
Language) – The language to use when starting the game. If left blank, defaults toLanguage.ENGLISH.theme (
Theme) – The theme to use when starting the game. If left blank, defaults toTheme.CHARACTERS.child_mode (
bool) – Whether to use child mode or not. Defaults to False.
- guesses#
A list of
Guessdictionary of guesses from greatest to least probability.- Type:
list[
Guess]
- timestamp#
A POSIX timestamp that is set when
Akinator.start()is called- Type:
- 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. IfNone, the language specified in the constructor will be used.theme (
Theme|None) – The theme to use when starting the game. IfNone, 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”. IfNone, the child mode specified in the constructor will be used.
- Returns:
The first question that Akinator is asking.
- Return type:
- 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.BACKwill callAkinator.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:
- answer:
- await back() str#
Go back to the previous question.
Note
Akinator.answer()will call this method for you if you pass inAnswer.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:
- await win() Guess#
Get Akinator’s current guesses based on the responses to the questions thus far.
This function will set:
Akinator.first_guessThe first guess that is returned
Akinator.guessesA 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:
- await end() Guess#
Alias to
Akinator.win().
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, and0.- For
Answer.NO, the following are valid: no,n, and1.- For
Answer.I_DONT_KNOW, the following are valid: i dont know,i don't know,idk, and2.- For
Answer.PROBABLY, the following are valid: probably,p, and3.- For
Answer.PROBABLY_NOT, the following are valid: probably not,pn, and4.- For
Answer.BACK, the following are valid: back,b, and5.
- For
- Raises:
InvalidAnswer – The answer you provided is not valid.
- Return type:
- 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
Languagefrom a string.The short form of a language (
enfor English,frfor French, etc.) is also accepted.- Parameters:
- Raises:
InvalidLanguage – The language you provided is not valid.
- Return type:
- 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
Themefrom a string.- Parameters:
theme (
str) –The theme to convert to
Theme.- For
Theme.CHARACTERS, the following are valid: characters,ch, andc.- For
Theme.OBJECTS, the following are valid: objects,obj, ando.- For
Theme.ANIMALS, the following are valid: animals, anda.
- For
- Raises:
InvalidTheme – The theme you provided is not valid.
- Return type:
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.