Skip to main content

quadkit-http

Outbound HTTP client for the Quadkit Framework.


Overview

Async outbound HTTP client for the Quadkit Framework. Provides a first-class async HTTP client backed by aiohttp, with connection pooling, typed request/ response contexts, interceptor chains, base URL clients, streaming support, and DI integration.

This package focuses on making outbound HTTP requests — for inbound web servers, use quadkit-web. Resilience patterns (retry, circuit breaker) are layered in through the optional provider, not built in by default.

Full documentation: docs.quadkit.dev

Install

uv add quadkit-http

Quick Start

from quadkit import Application
from quadkit.di.module import Module, module
from quadkit.http import HTTPModule, HTTPClientConfig


@module(imports=[HTTPModule.configure(HTTPClientConfig())])
class AppModule(Module):
    pass


async def main():
    async with Application.boot(modules=[AppModule]) as app:
        from quadkit.http import HTTPClient

        async with HTTPClient.session_context() as client:
            response = await client.get("https://api.example.com/users/123")
            if response.ok:
                user = await response.json()
                print(user)


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Configuration

Zero-config usage: Call HTTPModule.configure() with no arguments to use defaults.

Option 1 — YAML file

# application.yaml
http:
  pool:
    max_connections: 100
    max_keepalive_connections: 50
    timeout: 30.0
  trust_env: true
  cookie_jar: true
export QK_HTTP__POOL__MAX_CONNECTIONS=100
export QK_HTTP__POOL__TIMEOUT=30.0
export QK_HTTP__TRUST_ENV=true

Option 3 — Python

from quadkit.http import HTTPModule, HTTPClientConfig, ConnectionPoolConfig

HTTPModule.configure(
    HTTPClientConfig(
        pool=ConnectionPoolConfig(
            max_connections=100,
            timeout=30.0,
        ),
        trust_env=True,
        cookie_jar=True,
    )
)

Config reference

Field Default Env var Description
pool.max_connections 10 QK_HTTP__POOL__MAX_CONNECTIONS Total concurrent connections across all hosts
pool.max_keepalive_connections 5 QK_HTTP__POOL__MAX_KEEPALIVE_CONNECTIONS Keep-alive connections per host
pool.max_connections_per_host 10 QK_HTTP__POOL__MAX_CONNECTIONS_PER_HOST Max connections per individual host
pool.timeout 30.0 QK_HTTP__POOL__TIMEOUT Request timeout (seconds)
pool.ttl_dns_cache 300 QK_HTTP__POOL__TTL_DNS_CACHE DNS cache TTL (seconds)
proxy null QK_HTTP__PROXY HTTP/HTTPS proxy URL
trust_env True QK_HTTP__TRUST_ENV Read proxy settings from environment variables
cookie_jar True QK_HTTP__COOKIE_JAR Enable in-memory cookie jar

Module Factory Methods

Method Description
HTTPModule.configure(...) Configure with explicit HTTPClientConfig
HTTPModule.stub() No-op HTTPModule for unit testing

Key Features

  • Connection pooling — per-host limits, keepalive, DNS caching via aiohttp
  • Proxy support — HTTP/HTTPS with environment variable auto-detection
  • Cookie jar — optional, per-session in-memory cookie persistence
  • Streaming — StreamContext for large file downloads
  • Interceptor chains — composable auth, logging, metrics hooks
  • Type-safe contexts — RequestContext and ResponseContext typed models

Testing

from quadkit.contracts.web import HTTPClientProtocol, HttpResponse


class FakeHTTPClient(HTTPClientProtocol):
    async def get(self, url: str, **kwargs) -> HttpResponse:
        return HttpResponse(status=200, headers={}, body=b'{"id": 123}')


# Inject into service under test
service = UserService(http_client=FakeHTTPClient())

Key Source Files

File What it contains
src/quadkit/http/module.py HTTPModule with factory methods
src/quadkit/http/config.py HTTPClientConfig and ConnectionPoolConfig
src/quadkit/http/di/provider.py HTTPProvider — wires HTTP client into DI container
src/quadkit/http/client/ HTTPClient and BaseURLHTTPClient
src/quadkit/http/pool/ ConnectionPool (aiohttp connector abstraction)
src/quadkit/http/types.py RequestContext and ResponseContext typed models

Metadata

Release files for quadkit-http 0.0.43

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

Source distribution (sdist)

Source distribution for quadkit-http 0.0.43
File Size Uploaded Provenance
quadkit_http-0.0.43.tar.gz 66.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for quadkit-http 0.0.43
File Interpreter ABI Platform
quadkit_http-0.0.43-py3-none-any.whl Python 3 none any Details

Total release size: 117.3 kB

Release files / quadkit_http-0.0.43.tar.gz

Download URL quadkit_http-0.0.43.tar.gz
Size 66.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4c011b140c7e592d10e8ec37b6ef879e28a13d350cbbd288545cfe7d2f5d837b
BLAKE2b-256 checksum
How to use checksums
e7d57fb960cc7d25cb78b868d0515c0055f57aeb9eb399c3f307a75fc4112bd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.14

Release files / quadkit_http-0.0.43-py3-none-any.whl

Download URL quadkit_http-0.0.43-py3-none-any.whl
Size 51.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff6a1205c45c042ae3c41cc2d8d244ba6a3fa67917c190985771f38fcefa3c65
BLAKE2b-256 checksum
How to use checksums
6b3f12b4e9ee7fd3df5c75aa5a0291faeeb04bb28c40f717676562103c53ee27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.14

Security for quadkit-http 0.0.43

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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