← All projects
In developmentSelected project

lothc

A typed HTTP client for Python, built on Rust-backed pyreqwest.

  • Python
  • pyreqwest
  • Rust
  • pydantic
  • msgspec

Typed HTTP without losing ergonomics

lothc is a typed HTTP client that gives Python developers the familiar shape of requests and httpx while using pyreqwest’s Rust-backed transport underneath. It adds first-class typed request and response handling, so data crossing an HTTP boundary can be decoded directly into a validated model rather than an untyped dict.

uv add 'lothc[pydantic,msgspec]'

Install it from PyPI.

Typed at the boundary

Both async HTTPClient and sync SyncHTTPClient expose the same API. Responses can be decoded into pydantic models or msgspec structs; request parameters, headers, and multipart forms can use those same types.

from lothc import HTTPClient
from msgspec import Struct


class Pokemon(Struct):
    id: int
    name: str


async def main() -> None:
    async with HTTPClient.build(base_url="https://pokeapi.co/api/v2/") as client:
        pikachu = await client.get("pokemon/pikachu", response_data_type=Pokemon)

Performance with validation included

The published benchmarks measure 10,000 requests at concurrency 100 against a static JSON server, including typed decoding and validation rather than only raw bytes or untyped JSON. In those runs, msgspec decoding into a typed struct still came out ahead of decoding into an unvalidated dictionary—the validation isn’t free, but msgspec’s implementation more than absorbs the cost.

Read the benchmarks for the complete methodology, numbers, and caveats.

More than a wrapper

lothc includes typed SSE and NDJSON streaming, retries with Retry-After support, authentication helpers, cookies, redirect and proxy configuration, plus an explicit error hierarchy for transport and response failures.