Skip to content

HTTP

Use the same async client for external HTTP providers and internal container APIs. Endpoint declarations and site-specific parsers belong to the consuming package.

Installation

Terminal window
uv add common-http

Quick Start

from common_http import HttpClient
async with HttpClient.create(
base_url="http://solutions-agents:8000/",
max_concurrency=8,
) as http:
result = await http.post("/estimate", json={"items": []})
payload = result.unwrap().payload

Choose the entry point

NeedEntry point
Ordinary keyword configurationHttpClient.create(**settings)
Validated configuration or dictionaryHttpClient(config=...)
Discover accepted settingsHttpClient.configuration_schema()
Derive validated call overrideshttp.call_config(...)
Construct without network I/Ohttp.build_request(target, ...)
Bind and execute an endpoint or URLawait http.request(target, ...)
Simple GET or POSTawait http.get(url, ...), await http.post(url, ...)
Execute a resolved messageawait http.send(request)
Execute prepared messages in orderawait http.batch(requests)
Consume response chunksasync with http.stream(request)

PUT, PATCH, DELETE, HEAD and OPTIONS use request(method=...) or a prepared Request. Construction is unconnected; the first operation opens the client. Use an async context to close it predictably. Run these examples inside an async function or a notebook supporting top-level await. Python 3.12 or newer is required.

unwrap() requires successful execution, a complete decoded body and 2xx status. Inspect the result directly when a non-2xx response is meaningful to your caller.

Core concepts

  • Build independently with Request / Endpoint, or use http.build_request(...).
  • request builds and executes; send accepts a resolved Request.
  • batch returns input-aligned results through one execution runner.
  • call_config(...) creates a validated override; configuration_schema() exposes configuration fields and defaults. Objects and native dictionaries are accepted.
  • stream manages response bytes explicitly; buffered methods decode JSON/text/bytes.
  • Injected transports and authentication objects are borrowed. A created transport is owned and closed by the client. Closing rejects active operations.
  • HttpAuth is an HTTP interaction interface; shared token/refresh/storage logic belongs to a separate authentication implementation.

The container supplies reachable service addresses and credentials. The package reads no .env and contacts no secret manager.

Follow the guides

The executed client notebook demonstrates provider HTML, JSON services, batching, retries, authentication and streaming against local fixtures. These outputs do not establish that a live site will always return the required data.

During migration, this workspace consumes released common-execution/core from the old common repository. Their reserved directories are excluded from workspace resolution and publication. See the release guide.