Skip to main content

Synchronous and asynchronous clients to interact with PokeAPI

Project description

PyPokéClient

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

Python Pydantic


:notebook: 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 insights into the package.


:package: Installation

[!IMPORTANT]

  • This package requires python >= 3.12.
  • The package will published on PyPI as soon as it is ready.
# It is highly recommended to use uv
uv pip install git+https://github.com/RistoAle97/pokeapi-python-wrapper

# But you can also install the package simply with pip
pip install git+https://github.com/RistoAle97/pokeapi-python-wrapper

:hammer_and_wrench: How to use

You can choose whether to use a 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())

:floppy_disk: 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.

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.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-py3-none-any.whl (36.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pypokeclient-1.0.0.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.tar.gz
Algorithm Hash digest
SHA256 5776cd03d3e71d65431c933e540a5995e2a793f1402cf64bc9c2daf26bfb38a0
MD5 2c5322a1fff6ddb81ccbf3c731e50458
BLAKE2b-256 4df31984e7ed73139a7af13fb5cae19d4b5dabfa2854d87ce43357d8daa533d7

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypokeclient-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 36.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5287081b0395583fabd46ac8f50c4cf793a122b7961f707857ec243a0822eddf
MD5 7d25791b8d75d270100ae800f78aa6fe
BLAKE2b-256 22a10d865c5189d85ae176bf8aa3c9ceeaa01acafdfb0901fce062088e41fe09

See more details on using hashes here.

Provenance

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