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 simply with 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.0.post1.tar.gz (1.6 MB 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.0.post1-py3-none-any.whl (37.2 kB view details)

Uploaded Python 3

File details

Details for the file pypokeclient-1.0.0.post1.tar.gz.

File metadata

  • Download URL: pypokeclient-1.0.0.post1.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pypokeclient-1.0.0.post1.tar.gz
Algorithm Hash digest
SHA256 dabbece9c236010d6d46e9b990dec7eb8adde9473c7710c6375175409863080b
MD5 32ed00617eef9e4d63270280d72c30df
BLAKE2b-256 6a548d346cfdb61ad8e14406a8774d040504de1cd0d3850086a35f013b0ead11

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypokeclient-1.0.0.post1.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.0.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for pypokeclient-1.0.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 4747134891a84a03919fe813ba23014b2500394d3f325874b32d2730b392f7c2
MD5 ed2f061aac3d620ec73bcc08faf1d703
BLAKE2b-256 c88bcaf18bcc5007fd0f0f53e769346e7d7a28c60aa59ae2e8092268abbb849d

See more details on using hashes here.

Provenance

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