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.1.tar.gz (548.2 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.1-py3-none-any.whl (37.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pypokeclient-1.0.1.tar.gz
  • Upload date:
  • Size: 548.2 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.1.tar.gz
Algorithm Hash digest
SHA256 d5b55f91ccfc0084da7c25c61715718bff4b512c4f7afd09c2714f13f94a4a87
MD5 2c463dcd16ca903c1115e3619fd3beae
BLAKE2b-256 2f4bf96e080369756c5cdc4433c2ed2f9d87ef7d58144a5661933ac3b62e2359

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypokeclient-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 37.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 26ddbf2e381e7cf3d7e09fa2db838cfb194f5cff645cb3951f7c31d34aa3808b
MD5 90f6c7ba98ac6a4d7e123812eab58ce9
BLAKE2b-256 d65016ad7d197fb817dd1dc3dd79a3292ef9823d7f793249028630e410150fbf

See more details on using hashes here.

Provenance

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