An asynchronous framework to easily build a client-side API
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file stollen-0.4.2.tar.gz
.
File metadata
- Download URL: stollen-0.4.2.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15a38e9898c09a5d3d59c82cf8ca2d0410748dbd9ce3ada8f7bd29d8706847fe |
|
MD5 | 93bebc097f3289826ffc63f8d677e689 |
|
BLAKE2b-256 | 3d0f7b23636b2dde38e9f477b7503ee471091c91062d5bd22999ea1867dfd31f |
Provenance
The following attestation bundles were made for stollen-0.4.2.tar.gz
:
Publisher:
pypi-release.yml
on py-stollen/stollen
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
stollen-0.4.2.tar.gz
- Subject digest:
15a38e9898c09a5d3d59c82cf8ca2d0410748dbd9ce3ada8f7bd29d8706847fe
- Sigstore transparency entry: 147398782
- Sigstore integration time:
- Predicate type:
File details
Details for the file stollen-0.4.2-py3-none-any.whl
.
File metadata
- Download URL: stollen-0.4.2-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1e3f7f7eda4e0687fe094d85854c791432ff7533a043c772ca3acb87e697017 |
|
MD5 | b9a8f66153be070dfdf4ab317cd3c524 |
|
BLAKE2b-256 | ba60059f2504dfb671e829a6e89ce2834d85f2facef0d8bac15c8e1a8121a9a1 |
Provenance
The following attestation bundles were made for stollen-0.4.2-py3-none-any.whl
:
Publisher:
pypi-release.yml
on py-stollen/stollen
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
stollen-0.4.2-py3-none-any.whl
- Subject digest:
c1e3f7f7eda4e0687fe094d85854c791432ff7533a043c772ca3acb87e697017
- Sigstore transparency entry: 147398783
- Sigstore integration time:
- Predicate type: