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 requests-cache and aiohttp-client-cache documentations for more details about the caching system.
- It is not advised to use the same cache for both versions of the client as the two aforementioned packages work differently.
- Using the context manager is the preferred way when using a cache as the client will delete the expired responses from the cache on setup and will automatically close the session at the end.
import logging
from requests_cache import CachedSession
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)
# Fetch data
with Client(cached_session=CachedSession("pypokeclient-sync")) as sync_client:
pokemon = sync_client.get_pokemon("fuecoco")
pokemon = sync_client.get_pokemon("fuecoco")
The output will be the following
pypokeclient - INFO - Synchronous client is up and ready using CachedSession.
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 - Closed session for 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-1.0.2.tar.gz.
File metadata
- Download URL: pypokeclient-1.0.2.tar.gz
- Upload date:
- Size: 641.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
078482c7c57e90276337b4616e245486907e40d987f97d7521445b2cbaa2ba2e
|
|
| MD5 |
f7f9b4ad2797f3f30f8b147ae638ebd0
|
|
| BLAKE2b-256 |
36417be98f63b68de20c8de627ac890460b4b26fb0f91a0573d4918d22222695
|
Provenance
The following attestation bundles were made for pypokeclient-1.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-1.0.2.tar.gz -
Subject digest:
078482c7c57e90276337b4616e245486907e40d987f97d7521445b2cbaa2ba2e - Sigstore transparency entry: 621187939
- Sigstore integration time:
-
Permalink:
RistoAle97/pokeapi-python-wrapper@17bee86d7cde45b9928aa662f53e391b6172a1aa -
Branch / Tag:
refs/tags/1.02 - Owner: https://github.com/RistoAle97
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@17bee86d7cde45b9928aa662f53e391b6172a1aa -
Trigger Event:
release
-
Statement type:
File details
Details for the file pypokeclient-1.0.2-py3-none-any.whl.
File metadata
- Download URL: pypokeclient-1.0.2-py3-none-any.whl
- Upload date:
- Size: 37.6 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 |
53677d5de68be644284586dc35d6385d7664390e5aa2f024601167428b912299
|
|
| MD5 |
364cbff0e69760937d25e51c031c72f7
|
|
| BLAKE2b-256 |
c6ea9c38e6c74f78a30a7febb98801fb4376e274f92bc713d3952f4dd0427f0f
|
Provenance
The following attestation bundles were made for pypokeclient-1.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-1.0.2-py3-none-any.whl -
Subject digest:
53677d5de68be644284586dc35d6385d7664390e5aa2f024601167428b912299 - Sigstore transparency entry: 621187949
- Sigstore integration time:
-
Permalink:
RistoAle97/pokeapi-python-wrapper@17bee86d7cde45b9928aa662f53e391b6172a1aa -
Branch / Tag:
refs/tags/1.02 - Owner: https://github.com/RistoAle97
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@17bee86d7cde45b9928aa662f53e391b6172a1aa -
Trigger Event:
release
-
Statement type: