API reference¶
This section of the documentation outlines async_pokepy
’s API.
Client¶
-
async_pokepy.
connect
(base='https://pokeapi.co/api/v2/', **kwargs)[source]¶ Connect to the PokeAPI.
This method must be used to connect.
This returns a context manager mixin so it’s possible to both do this:
async with async_pokepy.connect() as client: # do stuff
and this
try: client = await async_pokepy.connect() # do stuff except ...: # handle exceptions finally: await client.close()
- Parameters
base (Optional[
str
]) – The base to use for all API requests, useful to edit if you want to host your own instance of the API. Defaults tohttps://pokeapi.co/api/v2/
.user_agent (Optional[
str
]) – The User-Agent header to use when making requests.loop (Optional[
asyncio.AbstractEventLoop
]) – The event loop used for HTTP requests, if no loop is providedasyncio.get_event_loop()
is used to get one.session (Optional[
aiohttp.ClientSession
]) – The client session to use during requests.
- Returns
The PokeAPI client.
- Return type
-
class
async_pokepy.
Client
[source]¶ The client representing a connection with the API.
It’s necessary to use
Connect()
to initiate this class.-
loop
¶ asyncio.AbstractEventLoop
– The event loop used for HTTP requests.
-
coroutine
get_ability
(query: Union[int, str]) → async_pokepy.types.ability.Ability[source]¶ Get a
Ability
from the API. The query can be both the name or the ID as a string or integer.The ability will be cached.
New in version 0.1.2a.
- Parameters
- Raises
PokeAPIException
– The request failed.NotFound
– The ability was not found.RateLimited
– More then 100 requests in one minute.
- Returns
The move searched for.
- Return type
-
coroutine
get_berry
(query: Union[int, str]) → async_pokepy.types.berry.Berry[source]¶ Get a
Berry
from the API. The query can be both the name or the ID as a string or integer.The berry will be cached.
New in version 0.1.3a.
- Parameters
- Raises
PokeAPIException
– The request failed.NotFound
– The berry was not found.RateLimited
– More then 100 requests in one minute.
- Returns
The berry searched for.
- Return type
-
coroutine
get_machine
(query: Union[int, str]) → async_pokepy.types.machine.Machine[source]¶ Get a
Machine
from the API. The query can only be the ID of the machine as a string or int.The machine will be cached.
New in version 0.1.5a.
- Parameters
- Raises
PokeAPIException
– The request failed.NotFound
– The machine was not found.RateLimited
– More then 100 requests in one minute.
- Returns
The machine searched for.
- Return type
-
coroutine
get_move
(query: Union[int, str]) → async_pokepy.types.move.Move[source]¶ Get a
Move
from the API. The query can be both the name or the ID as a string or integer.The move will be cached.
New in version 0.1.0a.
- Parameters
- Raises
PokeAPIException
– The request failed.NotFound
– The move was not found.RateLimited
– More then 100 requests in one minute.
- Returns
The move searched for.
- Return type
-
coroutine
get_pokemon
(query: Union[int, str]) → async_pokepy.types.pokemon.Pokemon[source]¶ Get a
Pokemon
from the API. The query can be both the name or the ID as a string or integer.The Pokémon will be cached.
- Parameters
- Raises
PokeAPIException
– The request failed.NotFound
– The Pokémon was not found.RateLimited
– More then 100 requests in one minute.
- Returns
The Pokèmon searched for.
- Return type
-
coroutine
get_pokemon_color
(query: Union[int, str]) → async_pokepy.types.pokemon.PokemonColor[source]¶ Get a
PokemonColor
from the API. The query can be both the name or the ID as a string or integer.The color will be cached.
New in version 0.1.7a.
- Parameters
- Raises
PokeAPIException
– The request failed.NotFound
– The color was not found.RateLimited
– More then 100 requests in one minute.
- Returns
The color searched for.
- Return type
-
coroutine
get_pokemon_habitat
(query: Union[int, str]) → async_pokepy.types.pokemon.PokemonHabitat[source]¶ Get a
PokemonHabitat
from the API. The query can be both the name or the ID as a string or integer.The habitat will be cached.
New in version 0.1.7a.
- Parameters
- Raises
PokeAPIException
– The request failed.NotFound
– The habitat was not found.RateLimited
– More then 100 requests in one minute.
- Returns
The habitat searched for.
- Return type
-
coroutine
read_sprite
(url: str) → bytes[source]¶ Read a sprite url’s sprite.
New in version 0.0.9a.
Changed in version 0.1.1a: The sprite is now cached.
-
coroutine
save_sprite
(url: str, fp, *, seek_begin: bool = True) → int[source]¶ Save a sprite url into a file-like object.
New in version 0.0.9a.
Changed in version 0.1.1a: The sprite is now cached.
- Parameters
url (
str
) – The image url of the sprite.fp (Union[
io.IOBase
,os.PathLike
]) – The file-like object to save the sprite to. This can be both a path to a file or a BinaryIO.seek_begin (
bool
) – Whether to seek to the beginning of the file after saving is done.
- Returns
The number of bytes written.
- Return type
-
Abstract base classes¶
An abstract base class (also known as an ABC
) is a class that
models can inherit to get their behaviour.
Abstract base classes cannot be instantiated.
-
class
async_pokepy.
UnNamedBaseObject
[source]¶ The abstract base class which all other full objects without name inherit from.
- Current list of full objects without name:
New in version 0.1.5a.
-
x[y]
Returns the object’s y attribute.
-
x == y
Check if two objects are the same.
-
x != y
Check if two objects are not the same.
-
class
async_pokepy.
BaseObject
[source]¶ The abstract base class which all other full objects inherit from.
This inherits from
UnNamedBaseObject
.Changed in version 0.1.5a: This now inherits from
UnNamedBaseObject
.-
str(x)
Returns the object’s name.
-
x[y]
Returns the object’s y attribute.
-
x == y
Check if two objects are the same.
-
x != y
Check if two objects are not the same.
-
-
class
async_pokepy.
AsyncIterator
[source]¶ Represents an abstrast asynchronous iterator.
New in version 0.1.0a.
-
async for x in y
Iterates over the contents of the async iterator.
-
coroutine
find
(predicate: Callable[[Any], bool]) → Union[Any, NoneType][source]¶ Search for an id or name in the iterator.
Changed in version 0.1.3: The function now takes a callable as it’s only parameter.
-
coroutine
find_similar
(name: str) → list[source]¶ Does a semi-fuzzy search on the iterator.
Changed in version 0.1.3: The results are now sorted by similarity.
-
coroutine
flatten
() → list[source]¶ Turn the iterator in a
list
.- Returns
The iterator’s items in a list.
- Return type
-
coroutine
next
() → NotImplemented[source]¶ Get the next item in the iterator.
This method must be implemented by a subclass.
- Raises
NoMoreItems
– There are no more items left in the iterator.- Returns
The next item from the iterator.
- Return type
-
Data Classes¶
Data classes all representing an API object, most of them just store data.
Danger
Just like ABCs these classes are not meant to be initiated by users.
Note
All data classes here have __slots__ defined which means that it is impossible to have dynamic attributes to them.
Pokemon¶
-
class
async_pokepy.
Pokemon
[source]¶ Represents a Pokémon object from the API.
-
str(x)
Returns the Pokémon’s name.
-
x[y]
Returns a Pokémon’s y attribute.
-
x == y
Check if two Pokémons are the same.
-
x != y
Check if two Pokémons are not the same.
-
abilities
¶ List[
PokemonAbility
] – A list ofPokemonAbility
the Pokémon could potentially have.
-
moves
¶ List[
PokemonMove
] – A list of moves along with learn methods and level details pertaining to specific version groups.
-
forms
¶ List[
NamedAPIObject
] – A list of forms the Pokémon can take on.
-
game_indices
¶ List[
VersionGameIndex
] – A list ofVersionGameIndex
relevent to Pokémon item by generation.
-
stats
¶ List[
PokemonStat
] – A list of base stat values for the Pokémon.
-
types
¶ List[
PokemonType
] – A list of details showing types the Pokémon has.
-
sprites
¶ PokemonSprites
– A set of sprites used to depict the Pokémon in the game.
-
species
¶ NamedAPIObject
– The species the Pokémon belongs to.
-
-
class
async_pokepy.
PokemonMove
[source]¶ Represents a move of a
Pokemon.
-
str(x)
Returns the move’s name.
-
move
¶ NamedAPIObject
– The move the Pokémon can learn.
-
version_group_details
¶ List[
PokemonMoveVersion
] – The details of the version in which the Pokémon can learn the move.
-
-
class
async_pokepy.
PokemonMoveVersion
[source]¶ Represents the version of a
PokemonMove
-
move_learn_method
¶ NamedAPIObject
– The method by which the move is learned.
-
version_group
¶ NamedAPIObject
– The version group in which the move is learned.
-
-
class
async_pokepy.
PokemonAbility
[source]¶ Represents an ability of a
Pokemon
.-
str(x)
Returns the ability’s name.
-
ability
¶ NamedAPIObject
– The ability.
bool
– Whether or not the ability is hidden.
-
-
class
async_pokepy.
PokemonStat
[source]¶ Represents a stat of a
Pokemon
.-
stat
¶ NamedAPIObject
– The stat.
-
-
class
async_pokepy.
PokemonType
[source]¶ Represents a type of a
Pokemon
.-
str(x)
Returns the type’s name.
-
type
¶ NamedAPIObject
– The type the Pokémon has.
-
-
class
async_pokepy.
PokemonSprites
[source]¶ Represents all of the possible sprites a
Pokemon
could have.Note
All of these attributes could be
None
or a friendly image url of the described sprite.-
for x in y
Returns an iterator over the sprites.
-
list(x)
Returns all of the sprites as a list, this will consume the iterator.
-
len(x)
Returns the number of sprites that are not
None
.
-
-
class
async_pokepy.
PokemonHeldItem
[source]¶ Represents an item held by a
Pokemon
.-
str(x)
Returns the ability’s name.
-
item
¶ NamedAPIObject
– The item the Pokémon holds.
-
version_details
¶ List[
PokemonHeldItemVersion
] – The details of the different versions in which the item is held.
-
-
class
async_pokepy.
PokemonHeldItemVersion
[source]¶ Represents the version of a
PokemonHeldItem
.-
version
¶ NamedAPIObject
– The version bound to the held item.
-
Color¶
-
class
async_pokepy.
PokemonColor
[source]¶ Represents the color of a
Pokemon
used for sorting one in a Pokédex.New in version 0.1.7a.
-
str(x)
Returns the color’s name.
-
x[y]
Returns a color’s y attribute.
-
x == y
Check if two colors are the same.
-
x != y
Check if two colors are not the same.
-
pokemon_species
¶ NamedAPIObject
– A list of the Pokémon species that have the color.
-
Habitat¶
-
class
async_pokepy.
PokemonHabitat
[source]¶ Represents an habitat of a
Pokemon
.New in version 0.1.7a.
-
str(x)
Returns the habitat’s name.
-
x[y]
Returns a habitat’s y attribute.
-
x == y
Check if two habitats are the same.
-
x != y
Check if two habitats are not the same.
-
pokemon_species
¶ List[
NamedAPIObject
] – A list of the Pokémon species that can be found in the habitat.
-
Move¶
-
class
async_pokepy.
Move
[source]¶ Represents a move object from the API.
New in version 0.1.0a.
-
str(x)
Returns the move’s name.
-
x[y]
Returns a move’s y attribute.
-
x == y
Check if two moves are the same.
-
x != y
Check if two moves are not the same.
-
priority
¶ int
– A value between -8 and 8. Sets the order in which the move is executed during battle.
-
contest_combos
¶ ContestComboSets
– A detail of normal and super contest combos that require the move.
-
contest_type
¶ NamedAPIObject
– The type of appeal the move gives a Pokémon when used in a contest.
-
damage_class
¶ NamedAPIObject
– The type of damage the move inflicts on the target, e.g. physical.
-
effect_entries
¶ List[
VerboseEffect
] – The effect of the move listed in different languages.
-
flavor_text_entries
¶ List[
MoveFlavorText
] – The flavor text of the move listed in different languages.
-
generation
¶ NamedAPIObject
– The generation in which the move was introduced.
-
meta
¶ MoveMetaData
– Metadata about the move.
-
past_values
¶ List[
PastMoveStatValues
] – A list of move value changes across version groups of the game.
-
stat_changes
¶ List[
MoveStatChange
] – A list of stats this move effects and how much it effects them.
-
effect_changes
¶ List[
AbilityEffectChange
] – The list of previous effects the move has had across version groups of the games.
-
target
¶ NamedAPIObject
– The type of target that will receive the effects of the move.
-
type
¶ NamedAPIObject
– The elemental type of the move.
-
machines
¶ MachineVersionDetail
– A list of the machines that teach this move.
-
-
class
async_pokepy.
MoveFlavorText
[source]¶ Represents the flavor text of a move associated with a language.
New in version 0.1.0a.
-
language
¶ NamedAPIObject
– The language the text is in.
-
version_group
¶ NamedAPIObject
– The version group that uses the text.
-
-
class
async_pokepy.
MoveMetaData
[source]¶ Represents the metadata about a move.
New in version 0.1.0a.
-
ailment
¶ NamedAPIObject
– The status ailment the move inflicts on it’s target.
-
category
¶ NamedAPIObject
– The category of move the move falls under, e.g. damage or ailment.
-
min_hits
¶ Optional[
int
] – The minimum number of times the move hits.None
if it always only hits once.
-
max_hits
¶ Optional[
int
] – The maximum number of times the move hits.None
if it always only hits once.
-
min_turns
¶ Optional[
int
] – The minimum number of turns the move continues to take effect.None
if it always only lasts one turn.
-
-
class
async_pokepy.
PastMoveStatValues
[source]¶ Represents changed values of a
Move
in a version group.New in version 0.1.0a.
-
effect_entries
¶ List[
VerboseEffect
] – The effect of the move listed in different languages.
-
type
¶ NamedAPIObject
– The elemental type of the move.
-
version_group
¶ NamedAPIObject
– The version group in which these move stat values were in effect.
-
-
class
async_pokepy.
ContestComboDetail
[source]¶ Represents a detail of moves that can be used to grain additional appeal points in contests.
New in version 0.1.0a.
-
use_before
¶ List[
NamedAPIObject
] – A list of moves to use before this move.
-
-
class
async_pokepy.
ContestComboSet
[source]¶ Represents a set of super and normal contest combos.
New in version 0.1.0a.
-
normal
¶ ContestComboDetail
– A detail of moves this move can be used before or after, granting additional appeal points in contests.
-
super
¶ ContestComboDetail
– A detail of moves this move can be used before or after, granting additional appeal points in super contests.
-
Ability¶
-
class
async_pokepy.
Ability
[source]¶ Represents an ability object from the API.
New in version 0.1.2a.
-
str(x)
Returns the Pokémon’s name.
-
x[y]
Returns a Pokémon’s y attribute.
-
x == y
Check if two Pokémons are the same.
-
x != y
Check if two Pokémons are not the same.
-
generation
¶ NamedAPIObject
– The generation the ability originated in.
-
effect_entries
¶ List[
VerboseEffect
] – The effect of the ability listed in different languages.
-
effect_changes
¶ List[
AbilityEffectChange
] – The list of previous effects the ability has had across version groups.
-
flavor_text_entries
¶ List[
AbilityFlavorText
] – The flavor text of the ability listed in different languages.
-
pokemon
¶ List[
AbilityPokemon
] – A list of Pokémon that could potentially have the ability.
-
-
class
async_pokepy.
AbilityPokemon
[source]¶ Reppresents an Pokémon of an
Ability
.bool
– Whether or not this a hidden ability for the Pokémon.
-
pokemon
¶ NamedAPIObject
– The Pokémon this ability could belong to.
-
class
async_pokepy.
AbilityEffectChange
[source]¶ Represents a past change of the effect of a move in a version group.
New in version 0.1.2a.
-
version_group
¶ NamedAPIObject
– The version group in which the previous effect of the ability originated.
-
-
class
async_pokepy.
AbilityPokemon
[source] Reppresents an Pokémon of an
Ability
.-
is_hidden
bool
– Whether or not this a hidden ability for the Pokémon.
-
slot
int
– The slot of the ability for the pokemon.
-
pokemon
NamedAPIObject
– The Pokémon this ability could belong to.
-
-
class
async_pokepy.
AbilityFlavorText
[source]¶ Represents the flavor text for a move, with a language and a version group.
. container:: operations
-
str(x)
Returns the actual flavor text.
-
language
¶ NamedAPIObject
– The language in which the text is in.
-
version_group
¶ NamedAPIObject
– The version group that uses this text.
-
Berry¶
-
class
async_pokepy.
Berry
[source]¶ Represents a berry object from the API.
-
str(x)
Returns the berry’s name.
-
x[y]
Returns a berry’s y attribute.
-
x == y
Check if two berries are the same.
-
x != y
Check if two berries are not the same.
-
growth_time
¶ int
– The time it takes the tree to grow one stage, in hours. Berry trees go through four of these growth stages before they can be picked.
-
firmness
¶ NamedAPIObject
– The firmness of the berry, used in making Pokéblocks or poffins.
-
soil_dryness
¶ int
– The speed at which the berry dries out the soil as it grows. A higher rate means the soil dries more quickly.
-
flavors
¶ List[
BerryFlavorMap
] – A list of references to each flavor a berry can have and the potency of each of those flavors in regard to the berry.
-
item
¶ NamedAPIObject
– Reference to the item specific data for this berry.
-
natural_gift_type
¶ NamedAPIObject
– The type inherited by “Natural Gift” when used with this Berry.
-
Machine¶
-
class
async_pokepy.
Machine
[source]¶ Represents a machine object from the API.
New in version 0.1.5a.
-
str(x)
Returns the machine item’s name.
-
x[y]
Returns a move’s y attribute.
-
x == y
Check if two moves are the same.
-
x != y
Check if two moves are not the same.
-
item
¶ NamedAPIObject
– The TM or HM item that corresponds to the machine.
-
move
¶ NamedAPIObject
– The move that is taught by the machine.
-
version_group
¶ NamedAPIObject
– The version group that the machine applies to.
-
Common¶
Some common data classes used by the API.
-
class
async_pokepy.
APIObject
[source]¶ Represents a partial API object with an ID.
New in version 0.1.3a.
-
class
async_pokepy.
NamedAPIObject
[source]¶ Represents a partial API object with a name and ID.
This inherits from
APIObject
.New in version 0.1.3a.
-
str(x)
Returns the object’s name.
-
-
class
async_pokepy.
Name
[source]¶ Represents a name associated with a language.
New in version 0.1.0a.
-
str(x)
Returns the name.
-
language
¶ NamedAPIObject
– The language in which the name is in.
-
-
class
async_pokepy.
Effect
[source]¶ Represents an effect description with a language.
New in version 0.1.2a.
-
str(x)
Returns the localized text.
-
language
¶ NamedAPIObject
– The language the effect is in.
-
-
class
async_pokepy.
VerboseEffect
[source]¶ Represents a short and long effect entry associated with a language.
New in version 0.1.0a.
-
language
¶ NamedAPIObject
– The language the effect is in.
-
Iterators¶
-
class
async_pokepy.
AsyncPaginationIterator
[source]¶ Represents an async iterator iterating over a pagination of objects.
-
async for x in y
Iterates over the contents of the async iterator.
New in version 0.1.0a.
-
coroutine
find
(predicate: Callable[[Any], bool]) → Union[Any, NoneType]¶ Search for an id or name in the iterator.
Changed in version 0.1.3: The function now takes a callable as it’s only parameter.
-
coroutine
find_similar
(name: str) → list¶ Does a semi-fuzzy search on the iterator.
Changed in version 0.1.3: The results are now sorted by similarity.
-
coroutine
flatten
() → list¶ Turn the iterator in a
list
.- Returns
The iterator’s items in a list.
- Return type
-
coroutine
next
() → Union[async_pokepy.types.common.NamedAPIObject, async_pokepy.types.common.APIObject][source]¶ Get the next object from the iterator.
- Raises
NoMoreItems
– There are no more items left... versionchanged:: 0.1.3a – This method now returns an Union of
NamedAPIObject
andAPIResource
.
- Returns
The partial object.
- Return type
Union[
NamedAPIObject
,APIResource
]
-
Exceptions¶
-
exception
async_pokepy.
PokeAPIException
[source]¶ Exception raised when an HTTP request is not successful.
-
response
¶ aiohttp.ClientResponse
– The failed HTTP response.
-
-
exception
async_pokepy.
NotFound
[source]¶ Exception raised when an HTTP request response code is equal to 404 NOT FOUND.
This inherits from
PokeAPIException
.
-
exception
async_pokepy.
Forbidden
[source]¶ Exception raised when an HTTP request response code is equal to 403 FORBIDDEN.
This inherits from
PokeAPIException
.
-
exception
async_pokepy.
RateLimited
[source]¶ Exception raised when an HTTP request is equal to 429 TOO MANY REQUESTS.
This exception will only raise if you surpass 100 requests per minutes, if you need more requests then that it would be better to host your own API instance.
This inherits from
PokeAPIException
.
-
exception
async_pokepy.
NoMoreItems
[source]¶ Exception raised when an AsyncIterator is empty.
This is usually catched to stop the iteration, unless you directly use the
AsyncPaginationIterator.next()
method you shouldn’t worry about it too much.New in version 0.1.0a.