akinator package#
Module contents#
Python bindings for akinator-rs, a wrapper around the undocumented akinator API
designed for easy implementation of an akinator game in code, providing a simple and easy to use API.
- class akinator.AsyncAkinator(*, theme=None, language=None, child_mode=None)#
Bases:
objectRepresents an async akinator game
Note
All attributes and methods are the same as the blocking
Akinatorclass but instead all methods should be awaitedParameters are also set as properties which also have a setter to change the values if necessary in the future
- Parameters:
theme (Optional[
Theme]) – the theme of the akinator game, would be one ofCharacters,AnimalsorObjectspass in using an answer enum, using thefrom_strclassmethod if necessary, defaults toCharacterslanguage (Optional[
Language]) – the language for the akinator game, refer to theLanguageenum, defaults toEnglishchild_mode (Optional[
bool]) – when set toTrue, NSFW content will not be provided, defaults toFalse
- answer(answer)#
This function is a coroutine.
Answers the akinator’s current question with the provided
answerand returns the next question- Parameters:
answer (
Answer) – the answer to the current question- Return type:
Optional[
str]- Raises:
RuntimeError – Something internal went wrong, this could be in this case: - missing required data to continue - request error: any sort of error when making the HTTP requests - updating the internal data fields errored (either a field was missing or was of the wrong type)
ValueError – Could not parse the API returned JSON properly (invalid, missing fields etc.)
Other api errors – Refer to the exceptions at the bottom of the page
- back()#
This function is a coroutine.
Goes back a question and returns said (current) question
- Return type:
Optional[
str]- Raises:
CantGoBackAnyFurther – Could not go back anymore, likely that we are already on the first question
RuntimeError – Something internal went wrong, this could be in this case: - missing required data to continue - request error: any sort of error when making the HTTP requests - updating the internal data fields errored (either a field was missing or was of the wrong type)
ValueError – Could not parse the API returned JSON properly (invalid, missing fields etc.)
Other api errors – Refer to the exceptions at the bottom of the page
- start_game()#
This function is a coroutine.
Starts the akinator game and returns the first question
- Return type:
Optional[
str]- Raises:
RuntimeError – Something internal went wrong, this could be in this case: - getting the starting timestamp failed - the data required to start the game such as the server url, frontaddr or game UID could not be found - request error: any sort of error when making the HTTP requests - updating the internal data fields errored (either a field was missing or was of the wrong type)
ValueError – Could not parse the API returned JSON properly (invalid, missing fields etc.)
Other api errors – Refer to the exceptions at the bottom of the page
- win()#
This function is a coroutine.
Tells the akinator to end the game and make its guess should be called once when the
progressionis high enough such as>=80.0and returns its best guess- Return type:
Optional[
Guess]- Raises:
RuntimeError – Something internal went wrong, this could be in this case: - missing required data to continue - request error: any sort of error when making the HTTP requests - updating the internal data fields errored (either a field was missing or was of the wrong type)
ValueError – Could not parse the API returned JSON properly (invalid, missing fields etc.)
Other api errors – Refer to the exceptions at the bottom of the page
- class akinator.Akinator(*, theme=None, language=None, child_mode=None)#
Bases:
objectRepresents an akinator game
Parameters are also set as properties which also have a setter to change the values if necessary in the future
- Parameters:
theme (Optional[
Theme]) – the theme of the akinator game, would be one ofCharacters,AnimalsorObjectspass in using an answer enum, using thefrom_strclassmethod if necessary, defaults toCharacterslanguage (Optional[
Language]) – the language for the akinator game, refer to theLanguageenum, defaults toEnglishchild_mode (Optional[
bool]) – when set toTrue, NSFW content will not be provided, defaults toFalse
- answer(answer)#
Answers the akinator’s current question with the provided
answerand returns the next question- Parameters:
answer (
Answer) – the answer to the current question- Return type:
Optional[
str]- Raises:
RuntimeError – Something internal went wrong, this could be in this case: - missing required data to continue - request error: any sort of error when making the HTTP requests - updating the internal data fields errored (either a field was missing or was of the wrong type)
ValueError – Could not parse the API returned JSON properly (invalid, missing fields etc.)
Other api errors – Refer to the exceptions at the bottom of the page
- back()#
Goes back a question and returns said (current) question
- Return type:
Optional[
str]- Raises:
CantGoBackAnyFurther – Could not go back anymore, likely that we are already on the first question
RuntimeError – Something internal went wrong, this could be in this case: - missing required data to continue - request error: any sort of error when making the HTTP requests - updating the internal data fields errored (either a field was missing or was of the wrong type)
ValueError – Could not parse the API returned JSON properly (invalid, missing fields etc.)
Other api errors – Refer to the exceptions at the bottom of the page
- start_game()#
Starts the akinator game and returns the first question
- Return type:
Optional[
str]- Raises:
RuntimeError – Something internal went wrong, this could be in this case: - getting the starting timestamp failed - the data required to start the game such as the server url, frontaddr or game UID could not be found - request error: any sort of error when making the HTTP requests - updating the internal data fields errored (either a field was missing or was of the wrong type)
ValueError – Could not parse the API returned JSON properly (invalid, missing fields etc.)
Other api errors – Refer to the exceptions at the bottom of the page
- win()#
Tells the akinator to end the game and make its guess should be called once when the
progressionis high enough such as>=80.0and returns its best guess- Return type:
Optional[
Guess]- Raises:
RuntimeError – Something internal went wrong, this could be in this case: - missing required data to continue - request error: any sort of error when making the HTTP requests - updating the internal data fields errored (either a field was missing or was of the wrong type)
ValueError – Could not parse the API returned JSON properly (invalid, missing fields etc.)
Other api errors – Refer to the exceptions at the bottom of the page
- class akinator.Guess#
Bases:
objecta model class representing an akinator’s guess not meant for the user to construct, but is returned in various properties and methods in the
Akinatorclass
- class akinator.Theme#
Bases:
objectAn enum class representing the theme of an akinator game
This is meant for the user to use to pass into the Akinator constructor, or to set the theme property
- Animals = <Theme theme="Animals">#
- Characters = <Theme theme="Characters">#
- Objects = <Theme theme="Objects">#
- from_str(theme)#
a classmethod to return a
Themeenum variant parsing from astruseful when you have external user input- Parameters:
theme (
str) – the string representation of the theme to parse from:: (.. note) – if an invalid string for the theme is given, no error will be raised instead it will just fallback to
Theme.Charactersas the default
- class akinator.Answer#
Bases:
objectAn enum class representing an answer given to the akinator
This is meant for the user to use to pass into methods such as Akinator.answer
- Idk = <Answer answer="Idk">#
- No = <Answer answer="No">#
- Probably = <Answer answer="Probably">#
- ProbablyNot = <Answer answer="ProbablyNot">#
- Yes = <Answer answer="Yes">#
- from_str(answer)#
a classmethod to return an
Answerenum variant parsing from astruseful when you have external user input- aliases for answer variants are also accepted (trims ws & case-insensitive):
yes | y | 0->Answer.Yesno | n | 1->Answer.Noi don(')?t know | idk | 2->Answer.Idkprobably | p | 3->Answer.Probablyprobably not | pn | 4->Answer.ProbablyNot
- Parameters:
answer (
str) – the string representation of the answer to parse from- Raises:
InvalidAnswer – raised if the provided answer cannot match one of the above (is invalid)
- class akinator.Language#
Bases:
objectAn enum class representing the language of the akinator game
This is meant for the user to use to pass into the Akinator constructor, or to set the language property
- Arabic = <Language lang="Arabic">#
- Chinese = <Language lang="Chinese">#
- Dutch = <Language lang="Dutch">#
- English = <Language lang="English">#
- French = <Language lang="French">#
- German = <Language lang="German">#
- Hebrew = <Language lang="Hebrew">#
- Indonesian = <Language lang="Indonesian">#
- Italian = <Language lang="Italian">#
- Japanese = <Language lang="Japanese">#
- Korean = <Language lang="Korean">#
- Polish = <Language lang="Polish">#
- Portugese = <Language lang="Portugese">#
- Russian = <Language lang="Russian">#
- Spanish = <Language lang="Spanish">#
- Turkish = <Language lang="Turkish">#
- from_str(language)#
a classmethod to return a
Languageenum variant parsing from astruseful when you have external user inputShort forms such as
enorfrare also accepted along with the full name- Parameters:
language (
str) – the string representation of the language to parse from- Raises:
InvalidLanguage – Raised if the given string is of an invalid language
- exception akinator.CantGoBackAnyFurther#
Bases:
ExceptionRaised when the akinator is already on the 1st question / there are no more questions to go back on
- exception akinator.InvalidAnswer#
Bases:
ExceptionRaised when an invalid answer string is used when instantiating a Language enum from str
- exception akinator.InvalidLanguage#
Bases:
ExceptionRaised when an invalid language string is used when instantiating a Language enum from str
- exception akinator.ConnectionError#
Bases:
ExceptionRaised when we fail the connect to the akinator servers for whatever reason
- exception akinator.NoMoreQuestions#
Bases:
ExceptionRaised when there are no more questions the akinator can offer
- exception akinator.TimeoutError#
Bases:
ExceptionRaised when the akinator session timed out waiting for a response