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.6.7.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stollen-0.6.7-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stollen-0.6.7.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for stollen-0.6.7.tar.gz
Algorithm Hash digest
SHA256 fbbaa1efaeba88203a6ab38d6e70384407781f5b8c3ced6b828edb9d3b9cb15d
MD5 5c4cf4b07e1bf65f40d0d2f6da961a95
BLAKE2b-256 adb9e2aaef5f1c06df40b71c877b04d6168418186790381429d95436353d7b3f

See more details on using hashes here.

Provenance

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

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: stollen-0.6.7-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for stollen-0.6.7-py3-none-any.whl
Algorithm Hash digest
SHA256 18f7c21fccbb57ab1bdfd1d38a8cda8d2450e7f50390473436c26ac6aa5d0dce
MD5 0a3f601b30700bfd44af160c95d150be
BLAKE2b-256 dfb0f01a6e9b417fcf82862463395d4d82994bdce239ec34f02a1309c335e7c9

See more details on using hashes here.

Provenance

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

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

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