Features
- Declarative API controller syntax
- Type-safe request/response handling
- Support for multiple HTTP clients (
wreq,aiohttp, or custom) - Comprehensive error handling
- Support for path parameters, query parameters, headers, body, JSON, form data, and file uploads
- Built on top of
msgspexfor fast serialization andkungfufor functional types (optional)
Getting started
# Base installation
pip install saronia
# With wreq client
pip install saronia[wreq]
# With aiohttp client
pip install saronia[aiohttp]
import asyncio
from dataclasses import dataclass
from uuid import UUID
from http import HTTPStatus
from kungfu import Error, Ok
from msgspex import Model
from saronia import API, APIError, APIResult, HTTPBearer, ModelStatusError, get, post
from wreq import Client
from saronia import WreqClient
Token = HTTPBearer
@dataclass
class Auth:
token: Token
cool_api = API[Auth] / "coolapi" / "v1"
class ValidationError(Model, ModelStatusError[HTTPStatus.INTERNAL_SERVER_ERROR]):
message: str
class NotFoundError(Model, ModelStatusError[HTTPStatus.NOT_FOUND]):
message: str
class Book(Model):
id: UUID
name: str
class CreateBookDTO(Model, kw_only=True):
book_id: UUID
name: str
@cool_api("/books", auth=Token)
class BooksController:
@get("/{book_id}", ValidationError, NotFoundError)
async def get_book_by_id(self, book_id: UUID) -> Book: ...
@post("/create", form=CreateBookDTO) # or as a Result
async def create_book(self) -> APIResult[Book, ValidationError | NotFoundError]: ...
books = BooksController()
async def main() -> None:
cool_api \
.build(WreqClient(base_url="https://www.example.com", request_timeout=45.0)) \
.auth(token=Token("abc123..."))
try:
book = await books.get_book_by_id(book_id=UUID("12345678-1234-5678-1234-567812345678"))
print("Book:", book)
except APIError as error:
print("API error:", error)
return
match await books.create_book(book_id=UUID("87654321-4321-8765-4321-876543218765"), name="New Book"):
case Ok(new_book):
print("New book:", new_book)
case Error(error):
print("API error:", error)
asyncio.run(main())
License
saronia is MIT licensed
Metadata
Release files for saronia 1.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| saronia-1.8.0.tar.gz | 72.4 kB | Without provenance | Details for saronia-1.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| saronia-1.8.0-py3-none-any.whl | Python 3 | none | any | Details for saronia-1.8.0-py3-none-any.whl |
Total release size: 102.3 kB
Release files / saronia-1.8.0.tar.gz
| Download URL | saronia-1.8.0.tar.gz |
|---|---|
| Size | 72.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fc9e8e9c8a2bd1dd07774d2f35accb1d3b00ac97b32edb7120e7bd9cce03181d
|
|
BLAKE2b-256 checksum How to use checksums |
29fa08bcec0bfacfc15213d2734244bd9626d28b486daea374e2f6e3c4038c60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / saronia-1.8.0-py3-none-any.whl
| Download URL | saronia-1.8.0-py3-none-any.whl |
|---|---|
| Size | 29.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bfa235ab98fbc0d768398b5ff98da7e880d01fdfcb217d14757a8b88ba9355f1
|
|
BLAKE2b-256 checksum How to use checksums |
0dd37a64d3599835b764dcbbcf3afcf899a794d777ab9c5127814f85d6d7329b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for saronia 1.8.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.