Skip to main content

An asynchronous framework to easily build a client-side API

Project description

MIT License PyPi status PyPi Package Version Downloads Supported python versions

Stollen is an asynchronous framework designed to streamline the process of building API clients, written in Python 3.9+ using aiohttp and pydantic. With a declarative approach, Stollen allows developers to define API methods, handle responses, and manage errors in a structured way, focusing on clarity and scalability.

Installation

pip install -U stollen

Example

from __future__ import annotations

import asyncio
import logging

from stollen import Stollen, StollenMethod, StollenObject
from stollen.enums import HTTPMethod
from stollen.exceptions import StollenAPIError


class CoingeckoAPIError(StollenAPIError):
    pass


class RateLimitError(CoingeckoAPIError):
    pass


class Coingecko(Stollen):
    def __init__(self) -> None:
        super().__init__(
            base_url="https://api.coingecko.com/api/v3",
            error_message_key=["status", "error_message"],
            general_error_class=CoingeckoAPIError,
            error_codes={429: RateLimitError},
            stringify_detailed_errors=False,
        )

    async def ping(self) -> GeckoSays:
        call: Ping = Ping()
        return await self(call)


class GeckoSays(StollenObject[Coingecko]):
    gecko_says: str


class Ping(
    StollenMethod[GeckoSays, Coingecko],
    http_method=HTTPMethod.GET,
    api_method="/ping",
    returning=GeckoSays,
):
    pass


async def main() -> None:
    logging.basicConfig(level=logging.DEBUG)
    async with Coingecko() as coingecko:
        gecko_says: GeckoSays = await coingecko.ping()
        logging.info(gecko_says)


if __name__ == "__main__":
    asyncio.run(main())

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

stollen-0.4.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

stollen-0.4-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file stollen-0.4.tar.gz.

File metadata

  • Download URL: stollen-0.4.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for stollen-0.4.tar.gz
Algorithm Hash digest
SHA256 df195173f096fc5e0a413f41d20cd5ba0bf69ec840512100e098816406bf1661
MD5 ffc2b0683d21040aeac94d3d352ca9d7
BLAKE2b-256 9374cf51501f861c2a8955ff35dc5f2d4cb42237f13a62467da1148ae391005c

See more details on using hashes here.

Provenance

The following attestation bundles were made for stollen-0.4.tar.gz:

Publisher: pypi-release.yml on py-stollen/stollen

Attestations:

File details

Details for the file stollen-0.4-py3-none-any.whl.

File metadata

  • Download URL: stollen-0.4-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for stollen-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5cbd4d7ebae0b2518085c1e59e03d323915fa2ee14be3e28f595d2e8db14ebe8
MD5 f3681b56174426da3914818da92c3433
BLAKE2b-256 a185f5fe7269db1caa0379b7506b30ca4f291f8bce1a56c7f517fe54afaeeaea

See more details on using hashes here.

Provenance

The following attestation bundles were made for stollen-0.4-py3-none-any.whl:

Publisher: pypi-release.yml on py-stollen/stollen

Attestations:

Supported by

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