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:

from pathlib import Path

from http_config import HTTPConfig, SSLConfig


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

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.11

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.11
File Size Uploaded
http_config-0.1.11.tar.gz 6.3 kB Details

Built distribution (wheel)

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

Total release size: 14.2 kB

Release files / http_config-0.1.11.tar.gz

Download URL http_config-0.1.11.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
167e79d1a7306c09938615a18087f6b4366d2559ddbf7867c166c9f83dce1379
BLAKE2b-256 checksum
How to use checksums
19d33ea63986588ac5b1861625f12a30a0a841ce5ccd17d6f9d2d1fbefe0de7f
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 12, 2026.

Transparency log

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

Download URL http_config-0.1.11-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72fb748a2f4f13a8e6871da0fa70afb20f71da29a24dfa81804a6da0df402733
BLAKE2b-256 checksum
How to use checksums
d17f27dfabe6ddc6094582dd6a24e1c84127429fe1a068f873486220b5429693
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 12, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.11 This release

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

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