Skip to main content

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.
  • pydantic-ai toolset — Expose a Service as agent-callable tools via ArrestToolset

Installation

uv

uv add arrest

pip

pip install arrest

OpenAPI support (optional)

uv add 'arrest[openapi]'

pydantic-ai toolset (optional)

uv add arrest --extra ai

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.


pydantic-ai toolset

Expose a Service as agent-callable tools by opting handlers in with tool_meta:

from arrest.ai.meta import ToolMeta
from arrest.ai.toolset import ArrestToolset
from pydantic_ai import Agent

users = Resource(
    name="users",
    route="/users",
    handlers=[
        H(GET, "/{user_id}", None, User, tool_meta=ToolMeta(name="get_user_by_id")),
    ],
)
service = Service(name="example", url="http://localhost:8080/api", resources=[users])

toolset = ArrestToolset(service)
agent = Agent(model="anthropic:claude-haiku-4-5", toolsets=[toolset])

result = await agent.run("Look up user abc123.")  # pydantic-ai enters/exits the toolset for you

See the pydantic-ai toolset docs for include/exclude filtering, retry behavior, and result truncation.


Contributing

See CONTRIBUTING.md.


License

MIT

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.2.tar.gz (728.6 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.2-py3-none-any.whl (38.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: arrest-0.2.2.tar.gz
  • Upload date:
  • Size: 728.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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.2.tar.gz
Algorithm Hash digest
SHA256 a0a441218caf30a013d36e9ca67705e3810788c335914c6ecc7e445a895773e6
MD5 9b20f923baa4c9d62d4f50bdf2d7eaba
BLAKE2b-256 315a582d3cdb45f7d52c4fb7c31b0fcbfdedddfed42bfb5466f006f54db69c31

See more details on using hashes here.

File details

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

File metadata

  • Download URL: arrest-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 38.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 17acf8b8c485a3b1bb610255e7f581c026198170ad14d4e787e569f135da055b
MD5 76daa93a9abaa876f9256f3748f7d5ac
BLAKE2b-256 3540b84361539722329746299a3d069c7a164b94cb339d61dd300f6b8b5a18c0

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 Sentry Error logging StatusPage Status page