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 quadkit-resilience, 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.42

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.42
File Size Uploaded Provenance
quadkit_http-0.0.42.tar.gz 75.7 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 126.9 kB

Release files / quadkit_http-0.0.42.tar.gz

Download URL quadkit_http-0.0.42.tar.gz
Size 75.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7ab18019f5e406ff5eb6e80bdc086b7f1c7100d8db57b6f2b3205170bb21334d
BLAKE2b-256 checksum
How to use checksums
3795eaa8f4f7a0f73f4e9302830f6f20a8969fcc3b138078a28f6d2f9103b1ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.14

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

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

Security for quadkit-http 0.0.42

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