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",
            use_method_placeholders=True,
            error_message_key=["status", "error_message"],
            general_error_class=CoingeckoAPIError,
            error_codes={429: RateLimitError},
        )

    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.INFO)
    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.1.4.tar.gz (11.4 kB view hashes)

Uploaded Source

Built Distribution

stollen-0.1.4-py3-none-any.whl (12.6 kB view hashes)

Uploaded Python 3

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