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)

# 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


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.0.2.tar.gz (641.6 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.0.2-py3-none-any.whl (37.6 kB view details)

Uploaded Python 3

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

Hashes for pypokeclient-1.0.2.tar.gz
Algorithm Hash digest
SHA256 078482c7c57e90276337b4616e245486907e40d987f97d7521445b2cbaa2ba2e
MD5 f7f9b4ad2797f3f30f8b147ae638ebd0
BLAKE2b-256 36417be98f63b68de20c8de627ac890460b4b26fb0f91a0573d4918d22222695

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypokeclient-1.0.2.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.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

Hashes for pypokeclient-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 53677d5de68be644284586dc35d6385d7664390e5aa2f024601167428b912299
MD5 364cbff0e69760937d25e51c031c72f7
BLAKE2b-256 c6ea9c38e6c74f78a30a7febb98801fb4376e274f92bc713d3952f4dd0427f0f

See more details on using hashes here.

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

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