Skip to main content

An asynchronous framework to easily build a client-side API

Project description

stollen is an asynchronous framework to easily build a client-side API.

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

Uploaded Source

Built Distribution

stollen-0.3-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stollen-0.3.tar.gz
  • Upload date:
  • Size: 15.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.3.tar.gz
Algorithm Hash digest
SHA256 1095b3b0e41fa2c735697b753dc99c409d19050a76fed594dbaacc4bb9a92415
MD5 eb4607707795e34571ffd6712c54632f
BLAKE2b-256 e22074a418f9a1d1a7ac8fc96590982c6097c78246e4a8c9cb8db4e34e9dc381

See more details on using hashes here.

Provenance

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

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

Attestations:

File details

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

File metadata

  • Download URL: stollen-0.3-py3-none-any.whl
  • Upload date:
  • Size: 17.5 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ad1fde525c9bd932df4e70e460dc01a21b7c45f26f00d4c92d2813ec7fd9ee74
MD5 a833ebbfbcc19e7a8a95f437a60c5df8
BLAKE2b-256 6325cc5249efa80fc4ecc4ee5da7b0aa79b96444decdf26890e16366701bc53d

See more details on using hashes here.

Provenance

The following attestation bundles were made for stollen-0.3-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