Skip to main content

Synchronous and asynchronous clients to interact with PokéAPI

Project description

PyPokéClient

Synchronous and asynchronous clients to fetch data from PokéAPI.

Python Pydantic

PyPI Python versions


📌 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)

# Set up a cached session
session = CachedSession("pypokeclient-sync")  # by default it will use a sqlite db

# Fetch data
with Client(cached_session=session) 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 - 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 - [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 synchronous client.

📝 License

This project is MIT licensed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypokeclient-1.1.0.tar.gz (642.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypokeclient-1.1.0-py3-none-any.whl (38.4 kB view details)

Uploaded Python 3

File details

Details for the file pypokeclient-1.1.0.tar.gz.

File metadata

  • Download URL: pypokeclient-1.1.0.tar.gz
  • Upload date:
  • Size: 642.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pypokeclient-1.1.0.tar.gz
Algorithm Hash digest
SHA256 69e494934d8979ba452cbeb761a0c828a0f3f26e1d306436a029ab473cf3758d
MD5 6d3f2c324645d31f903475d96a642956
BLAKE2b-256 74c29a17cb2d907699f188356942c99d484839bba1d8cbcb85c78186cf9aa32b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypokeclient-1.1.0.tar.gz:

Publisher: publish-to-pypi.yml on RistoAle97/pokeapi-python-wrapper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypokeclient-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pypokeclient-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 38.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pypokeclient-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55cd3c66052bdd207d3565f0d4e92ff7718f5cc56f520064264ca0a500243495
MD5 fdf9aab7b527cceabb0a8b2ab550cfc3
BLAKE2b-256 7e4a988712f7010071a26adc703d9b81013d9594c8fc9c4681a19386bb37e25d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypokeclient-1.1.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on RistoAle97/pokeapi-python-wrapper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page