This project is a simple, sample python SDK to simplify working with PokeAPI. Specifically, the following endpoints:
GET https://pokeapi.co/api/v2/pokemon/{id or name}/
GET https://pokeapi.co/api/v2/generation/{id or name}/
It is highly recommended to use a virtual environment. You can use whichever method you desired, but I prefer venv.
With your virtual environment active
pip install git+https://github.com/PandaBacon21/pokeSDK.git
from pokemon_sdk import PokeAPI
-
get_pokemon(args?): retrieves data about pokemon. If no arguments are passed, it will return ALL pokemon. Passidornameto retrieve data about a specific pokemon.argsid?: retrieve pokemon by unique ID, optionalname?: retrieve pokemon by name, optional
-
get_generaion(args?): retrieves data about pokemon generations. If no arguments are passed, it will return ALL generations. Passidornameto retrieve data about a specific generation.argsid?: retrieves generation by unique ID, optionalname?: retrieves generation by name, optional
Response objects can be further explored using these fields
- Response to
get_pokemon({id or name}).id: int.name: str.height: int.is_default: bool.order: int.weight: int.abilities: list.forms: list.game_indices: list.held_items: list.location_area_encounters: str.moves: list.past_types: list.sprites: dict.cries: dict.species: dict.stats: list.types: list
- Response to
get_generation({id or name}).id: int.name: str.abilities: list.names: list.main_region: dict.moves: list.pokemon_species: list.types: list.version_groups: list
- Response to
get_pokemon()orget_generation()- no arguments.count: int.results: list
from pokemon_sdk import PokeAPI
client = PokeAPI()
generations = client.get_generation()
if generations:
print(generations.count)
9
from pokemon_sdk import PokeAPI
client = PokeAPI()
pokemon = client.get_pokemon('bulbasaur')
if pokemon:
name = pokemon.name
moves = pokemon.moves
moves_list = []
for move in moves:
moves_list.append(move['move']['name'])
print(f"{name}'s moves: \n {moves_list}")
bulbasaur's moves:
['razor-wind', 'swords-dance', 'cut', 'bind', 'vine-whip', 'headbutt', 'tackle', 'body-slam', 'take-down', 'double-edge', 'growl', 'strength', 'mega-drain', 'leech-seed', 'growth', 'razor-leaf', 'solar-beam', 'poison-powder', 'sleep-powder', 'petal-dance', 'string-shot', 'toxic', 'rage', 'mimic', 'double-team', 'defense-curl', 'light-screen', 'reflect', 'bide', 'sludge', 'skull-bash', 'amnesia', 'flash', 'rest', 'substitute', 'snore', 'curse', 'protect', 'sludge-bomb', 'mud-slap', 'outrage', 'giga-drain', 'endure', 'charm', 'false-swipe', 'swagger', 'fury-cutter', 'attract', 'sleep-talk', 'return', 'frustration', 'safeguard', 'sweet-scent', 'synthesis', 'hidden-power', 'sunny-day', 'rock-smash', 'facade', 'nature-power', 'helping-hand', 'ingrain', 'knock-off', 'secret-power', 'weather-ball', 'grass-whistle', 'bullet-seed', 'magical-leaf', 'natural-gift', 'worry-seed', 'seed-bomb', 'energy-ball', 'leaf-storm', 'power-whip', 'captivate', 'grass-knot', 'venoshock', 'acid-spray', 'round', 'echoed-voice', 'grass-pledge', 'work-up', 'grassy-terrain', 'confide', 'grassy-glide', 'tera-blast', 'trailblaze']
Testing is included in the repo with pytest and test script included in tests/test_sdk.py. Testing is not however included in the package via PIP. To run the integrations tests, clone the repo.
git clone https://github.com/PandaBacon21/pokeSDK.git
Once cloned, cd into that directory and install dependencies (again, I recommend using a virtual environment)
pip install -r requirements.txt
In the root directory run
pytest
or pytest -v for the detailed output
This SDK uses Pydantic to validate API responses, ensuring the data matches the expected structure. It also allows access to response attributes using dot notation -
pokemon.movesorgeneration.countfor example. This makes it simple to extract specific attributes. However, further nested data, such as lists or dictionaries within these attributes still require bracket notation -pokemon.moves['move']['name']for example.
This project is licensed under the MIT License and provided as is LICENSE.