Synchronous and asynchronous clients to interact with PokéAPI
Project description
📌 Features
- Coverage: all PokéAPI endpoints are covered.
- Data validation: uses Pydantic dataclasses for the API implementation.
- Flexibility: can choose between synchronous and asynchronous clients.
- Caching: can employ a local cache system for faster responses and to respect PokéAPI Fair Use policy.
Please have a look at the documentation for more details about the package.
📦 Installation
# It is highly recommended to use uv
uv pip install pypokeclient
# But you can also install the package via pip
pip install pypokeclient
🛠️ How to use
You can choose whether to use the synchronous client
from pypokeclient import Client
# Simple usage
client = Client()
pokemon = client.get_pokemon("fuecoco")
# Or with context manager
with Client() as client:
pokemon = client.get_pokemon("fuecoco")
or the asynchronous one
import asyncio
from pypokeclient import AsyncClient
async def fetch_data():
# Simple usage
client = AsyncClient()
pokemon = await client.get_pokemon("fuecoco")
# With context manager
async with AsyncClient() as client:
pokemon = await client.get_pokemon("fuecoco")
asyncio.run(fetch_data())
💾 Caching the results
[!IMPORTANT] Please refer to the hishel documentation for more details about the caching system.
import logging
from hishel import SyncSqliteStorage
from hishel.httpx import SyncCacheClient
from pypokeclient import Client
# Set up the logger
logger = logging.getLogger("pypokeclient")
logger.setLevel(logging.INFO)
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter("%(name)s - %(levelname)s - %(message)s"))
logger.addHandler(console_handler)
# Set up the underlying HTTP client
http_client = SyncCacheClient(
storage=SyncSqliteStorage(database_path="pypokeclient_cache.db")
)
# Fetch data
with Client(http_client) as sync_client:
pokemon = sync_client.get_pokemon("fuecoco")
pokemon = sync_client.get_pokemon("fuecoco")
# The sprites are cached too
sprite = sync_client.get_sprite(pokemon.sprites.front_default)
sprite = sync_client.get_sprite(pokemon.sprites.front_default)
# You can also save the sprites locally if needed
sprite.save("fuecoco.png")
The output will be the following
pypokeclient - INFO - The synchronous client is ready and using the cache at .cache\hishel\pypokeclient_cache.db'.
pypokeclient - INFO - [200] Request to https://pokeapi.co/api/v2/pokemon/fuecoco.
pypokeclient - INFO - [200] Cached request to https://pokeapi.co/api/v2/pokemon/fuecoco.
pypokeclient - INFO - [200] Request to https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/909.png.
pypokeclient - INFO - [200] Cached request to https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/909.png.
pypokeclient - INFO - Closed session for the synchronous client.
📝 License
This project is MIT licensed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pypokeclient-2.0.2.tar.gz.
File metadata
- Download URL: pypokeclient-2.0.2.tar.gz
- Upload date:
- Size: 589.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7706b3bbbd39546a51c4be957e70281e118b2151001374e9a02e22fedbf3b57d
|
|
| MD5 |
2ccea2d9f3bb18fa08e110e248a5621b
|
|
| BLAKE2b-256 |
7cf9826162cde7fd9c05dc7ac352085c5e3f432d035a4ea5db0248f779876ee7
|
Provenance
The following attestation bundles were made for pypokeclient-2.0.2.tar.gz:
Publisher:
publish-to-pypi.yml on RistoAle97/pokeapi-python-wrapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pypokeclient-2.0.2.tar.gz -
Subject digest:
7706b3bbbd39546a51c4be957e70281e118b2151001374e9a02e22fedbf3b57d - Sigstore transparency entry: 1225061549
- Sigstore integration time:
-
Permalink:
RistoAle97/pokeapi-python-wrapper@c4b8b54bf42ef2b68fde900992688609a8893810 -
Branch / Tag:
refs/tags/2.0.2 - Owner: https://github.com/RistoAle97
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@c4b8b54bf42ef2b68fde900992688609a8893810 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pypokeclient-2.0.2-py3-none-any.whl.
File metadata
- Download URL: pypokeclient-2.0.2-py3-none-any.whl
- Upload date:
- Size: 39.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2105fe5b1b884387dc63675846fb9c23ca5586eea7da6920ac458133e70b8569
|
|
| MD5 |
13f92c796da267356d9afc2de89cebfa
|
|
| BLAKE2b-256 |
5fd96aed33345f57b1fd5d3b9d5753b741c9743df74aeeafe997e051b3b174fa
|
Provenance
The following attestation bundles were made for pypokeclient-2.0.2-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on RistoAle97/pokeapi-python-wrapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pypokeclient-2.0.2-py3-none-any.whl -
Subject digest:
2105fe5b1b884387dc63675846fb9c23ca5586eea7da6920ac458133e70b8569 - Sigstore transparency entry: 1225061731
- Sigstore integration time:
-
Permalink:
RistoAle97/pokeapi-python-wrapper@c4b8b54bf42ef2b68fde900992688609a8893810 -
Branch / Tag:
refs/tags/2.0.2 - Owner: https://github.com/RistoAle97
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@c4b8b54bf42ef2b68fde900992688609a8893810 -
Trigger Event:
release
-
Statement type: