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

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.44
File Size Uploaded Provenance
quadkit_http-0.0.44.tar.gz 66.1 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 117.3 kB

Release files / quadkit_http-0.0.44.tar.gz

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

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

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

Security for quadkit-http 0.0.44

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