Declarative, type-safe HTTP client with Pydantic validation
Project description
Arrest
- Documentation: https://s-bose.github.io/arrest/
Arrest is a type-safe HTTP client for Python built on httpx and Pydantic. Define your REST APIs declaratively — routes, request/response models, retries, and error handling in one place — and get full static analysis, autocomplete, and runtime validation for every call.
Features
- Type-safe — Pydantic models, dataclasses, dicts, lists, and XML models for request and response validation
- Declarative — Services, resources, and handlers keep your API surface organized
- JSON, Form, Multipart, and XML —
application/json,application/x-www-form-urlencoded,multipart/form-data, andapplication/xmlcontent types - Retries — Built-in exponential backoff via tenacity, or transport-level retries via httpx
- Exception handling — Custom hooks per exception type, clean
RequestErrorfor transport failures - OpenAPI codegen — Generate Arrest services and Pydantic models from an OpenAPI spec
H()helper — IDE-friendly handler definitions with keyword-argument autocomplete- Unified
Response[T]— One response type for all HTTP status codes withis_success,is_client_error, etc.
Installation
uv
uv add arrest
pip
pip install arrest
OpenAPI support (optional)
uv add 'arrest[openapi]'
Quickstart
from arrest import H, Resource, Service, GET, POST
user = Resource(
route="/users",
handlers=[
H(GET, "/"),
H(GET, "/{user_id}"),
H(POST, "/", request=NewUserRequest, response=UserResponse),
],
)
svc = Service(
name="api",
url="https://api.example.com/v1",
resources=[user],
)
# GET /users
resp = await svc.users.get("/")
if resp.is_success:
print(resp.data)
# POST /users with type-safe request body
resp = await svc.users.post("/", request=NewUserRequest(name="Alice", email="a@b.com"))
XML, Form, and File uploads
from pydantic_xml import BaseXmlModel, element
from arrest.params import Form, File
from arrest.types import UploadFile
# XML request/response
class XmlPayload(BaseXmlModel, tag="payload"):
key: str = element()
value: str = element()
# Form-encoded
class Login(BaseModel):
username: str = Form(...)
password: str = Form(...)
# Multipart file upload
class Profile(BaseModel):
name: str = Form(...)
avatar: UploadFile = File(...)
OpenAPI codegen
arrest --url https://petstore3.swagger.io/api/v3/openapi.json -o ./generated
Generates models.py, resources.py, and services.py from any OpenAPI spec.
Contributing
See CONTRIBUTING.md.
License
MIT
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file arrest-0.2.0.tar.gz.
File metadata
- Download URL: arrest-0.2.0.tar.gz
- Upload date:
- Size: 708.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f383fb9e6373d3a23a49d25d50d270a279f2b5c19e6e330d57e5df7c61696b69
|
|
| MD5 |
d82ec8dda60ce163c86f131775fab29a
|
|
| BLAKE2b-256 |
45ef85fa5e85ace290e7b68156268b98147f00dc1966982d19459f04b7992817
|
File details
Details for the file arrest-0.2.0-py3-none-any.whl.
File metadata
- Download URL: arrest-0.2.0-py3-none-any.whl
- Upload date:
- Size: 31.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02285009cf7916ba6436fecd6bb55a5a2cd88ee1aa91172d18737e7852b08dd9
|
|
| MD5 |
15bb2ad3b4db7475b9dce543d8cee97e
|
|
| BLAKE2b-256 |
d7291ebf7a5f40408899cf156e6f5dcfeec2334810f00caf2f28381f486d69db
|