Skip to main content

Declarative, type-safe HTTP client with Pydantic validation

Project description

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 XMLapplication/json, application/x-www-form-urlencoded, multipart/form-data, and application/xml content types
  • Retries — Built-in exponential backoff via tenacity, or transport-level retries via httpx
  • Exception handling — Custom hooks per exception type, clean RequestError for 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 with is_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arrest-0.2.1.tar.gz (708.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arrest-0.2.1-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

Details for the file arrest-0.2.1.tar.gz.

File metadata

  • Download URL: arrest-0.2.1.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

Hashes for arrest-0.2.1.tar.gz
Algorithm Hash digest
SHA256 26fd328e8263df39cbc93d6e8d785b4895c2474a81596f2bfd4cdd6a3de59f18
MD5 91472af42d4876adaf3385a1b7903cba
BLAKE2b-256 c12c2095e4ab7c5263734c5c1bf660ea6287658c1ee7c87a58e02bb530a8dda2

See more details on using hashes here.

File details

Details for the file arrest-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: arrest-0.2.1-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

Hashes for arrest-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4cd3931518bac85c8c3b6d323d90e51dafe5fc85f44c658a99ebd7f945e59b9e
MD5 57b8e2a1eca379ca7cce0b9be7616f64
BLAKE2b-256 805124e741d3267d3d88ce9bb816e475e5d9a6729658dd614994bbeed8654894

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page