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.1.12a1.tar.gz (702.1 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.1.12a1-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

Details for the file arrest-0.1.12a1.tar.gz.

File metadata

  • Download URL: arrest-0.1.12a1.tar.gz
  • Upload date:
  • Size: 702.1 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.1.12a1.tar.gz
Algorithm Hash digest
SHA256 cb387d5c29f2188a5a1a02f90f1564ac9c59bb6bbb5e3d626f930dfcce5e3378
MD5 36f82f264f4f45b697c23b91c65bb569
BLAKE2b-256 ae9e6bcdfc5b82cb40721e7cc547b16b5f1ca6ddf4ff92397430857a715695ea

See more details on using hashes here.

File details

Details for the file arrest-0.1.12a1-py3-none-any.whl.

File metadata

  • Download URL: arrest-0.1.12a1-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.1.12a1-py3-none-any.whl
Algorithm Hash digest
SHA256 008761c4a3804b62b2f39cadfb47442b36c466cf77cbc77fc8d095046d133bb4
MD5 636aeab4676e3c055e861d5deef4bf1c
BLAKE2b-256 f9eccbe0403c7b8e2b10d25ce1a3a1bf9dc416496c66922ea07a8d8a3f6d05f9

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