Skip to main content

HTTP Config

Shared, typed configuration for Python HTTP clients. Keep proxy, timeout, connection-limit, TLS, and request logging settings in one Pydantic model and reuse them across client integrations.

The core configuration models are client-library independent. The project currently provides an integration for HTTPX2, with support for additional HTTP libraries planned for the future.

Installation

Using uv:

uv add "http-config[httpx2]"

Using pip:

python -m pip install "http-config[httpx2]"

The httpx2 extra installs the current HTTPX2 integration. The configuration models are available without any client-library extra, allowing future integrations to be added independently.

Quick Start

from datetime import timedelta

from http_config import HTTPConfig, LimitConfig, TimeoutConfig
from http_config.httpx2 import sync_client


config = HTTPConfig(
    timeout=TimeoutConfig(
        timeout=timedelta(seconds=10),
        connect_timeout=timedelta(seconds=3),
    ),
    limits=LimitConfig(
        max_connections=50,
        max_keepalive_connections=10,
    ),
)

with sync_client(config) as client:
    response = client.get("https://httpbin.org/get")
    response.raise_for_status()
    print(response.json())

For asynchronous code, use async_client:

from http_config.httpx2 import async_client


async def fetch() -> dict:
    async with async_client() as client:
        response = await client.get("https://httpbin.org/get")
        response.raise_for_status()
        return response.json()

Configuration

HTTPConfig supports these settings:

Setting Type Description
proxy str | None Proxy URL passed to the active client integration.
timeout timedelta | False | TimeoutConfig | None Overall or per-operation timeout. False disables the timeout.
limits LimitConfig | None Maximum open and keep-alive connections.
ssl bool | SSLConfig | None TLS verification mode and custom certificate sources.
log_path Path | None Directory where request and response files are recorded by supported integrations.

Merging Configuration

The configuration models use pydantic-merge. Use model_merge() to create a validated copy with updates applied recursively. Nested configuration is merged instead of replaced, so an update to one timeout value preserves the other timeout values:

from datetime import timedelta

from http_config import HTTPConfig, TimeoutConfig


base = HTTPConfig(
    timeout=TimeoutConfig(
        timeout=timedelta(seconds=10),
        read_timeout=timedelta(seconds=5),
    ),
)
updated = base.model_merge(
    HTTPConfig(
        timeout=TimeoutConfig(connect_timeout=timedelta(seconds=3)),
    )
)

assert updated.timeout.timeout == timedelta(seconds=10)
assert updated.timeout.read_timeout == timedelta(seconds=5)
assert updated.timeout.connect_timeout == timedelta(seconds=3)

TLS

The default is normal certificate verification. Set ssl=False to disable verification, or provide a custom CA file, directory, or certificate data with SSLConfig:

If certifi is installed, its CA bundle is used automatically when no explicit cafile is configured. Install it separately with uv add certifi or python -m pip install certifi. An explicit cafile takes precedence; set ignore_certifi=True to opt out of the automatic certifi fallback.

from pathlib import Path

from http_config import HTTPConfig, SSLConfig


config = HTTPConfig(
    ssl=SSLConfig(
        cafile=Path("certificates/ca.pem"),
    ),
)

To disable the automatic certifi fallback:

from http_config import HTTPConfig, SSLConfig


config = HTTPConfig(ssl=SSLConfig(ignore_certifi=True))

SSLConfig.create() is useful when settings come from optional application configuration:

ssl_setting = SSLConfig.create(insecure=False, cafile=Path("ca.pem"))

Request Logging

Set log_path to enable file-based transport logging. The directory is created automatically. Each request gets JSON header files and body files when a body is present, paired by a timestamp-based prefix and request index.

from pathlib import Path

from http_config import HTTPConfig
from http_config.httpx2 import sync_client


config = HTTPConfig(log_path=Path("http-logs"))
with sync_client(config) as client:
    client.get("https://httpbin.org/get")

HTTPX2 Middleware and Authentication

The current HTTPX2 client factories accept an optional transport middleware function and either an HTTPX auth object or a factory that receives the client:

import httpx2

from http_config.httpx2 import sync_client


def middleware(transport: httpx2.BaseTransport) -> httpx2.BaseTransport:
    return transport


with sync_client(
    middleware=middleware,
    auth=httpx2.BasicAuth("user", "password"),
) as client:
    response = client.get("https://example.com")

Development

Install the test dependencies and run the suite with:

uv sync --group test
uv run pytest
uv run ruff check

License

This project is available under the MIT License.

Release files for http-config 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for http-config 0.1.8
File Size Uploaded
http_config-0.1.8.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for http-config 0.1.8
File Interpreter ABI Platform
http_config-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / http_config-0.1.8.tar.gz

Download URL http_config-0.1.8.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f3a51d30b9f5c3b6beec603515a8c592f1bb5b9655d65f1aeecb33e68259cd6b
BLAKE2b-256 checksum
How to use checksums
29a186d6ec305052062e03784b8e440d810c7c0f35d29c55a4b4faa969b44373
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / http_config-0.1.8-py3-none-any.whl

Download URL http_config-0.1.8-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e240bc68c7bf8d052f31f3ab6bbe33c5f4d1bfdfd5b5d4e5f0b90abe848553b2
BLAKE2b-256 checksum
How to use checksums
8b17db1d963a0e9451ef04623ce4eaea5e987d7932f5f4ec95bc7fa658f99d80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page