• Joined on 2025-02-10

aiohttpx (1.4.0)

Published 2026-01-16 09:46:33 +03:00 by Miwory in Miwory/AioHTTPX

Installation

pip install --index-url  aiohttpx

About this package

Custom HTTPX client with aiohttp transport, rate limiter and caching

AioHTTPX

AioHTTPX is an internal async HTTP client built on top of httpx.AsyncClient, using aiohttp as the transport layer for improved async performance. It also adds Redis-backed rate limiting and response caching at the transport level.


What it provides

  • AioHTTPXClient — a drop-in replacement for httpx.AsyncClient
  • aiohttp-based async transport
  • Optional rate limiting (Redis)
  • Optional response caching (Redis, TTL via headers)

Installation (internal)

Configure pip with your private index:

[global]
index-url = https://git.miwory.dev/api/packages/Miwory/pypi/simple
username = <USERNAME>
password = <PASSWORD>

Then install:

pip install aiohttpx

Usage

Basic client (no Redis)

from aiohttpx import AioHTTPXClient

async with AioHTTPXClient() as client:
    r = await client.get("https://example.com")
    print(r.text)

This uses:

  • aiohttp.ClientSession under the hood
  • httpx-compatible request / response API

Rate limiting

Rate limiting is optional and requires Redis.

client = AioHTTPXClient(
    redis_url="redis://localhost:6379",
    key="my-rate-limit-key",
    limit=60,  # requests per minute
)

How it works:

  • Token-based limiting using Redis time
  • Requests exceeding the limit are delayed and retried
  • Implemented in AsyncRateLimit

Response caching

Caching is also optional and Redis-backed.

client = AioHTTPXClient(
    redis_url="redis://localhost:6379",
)

To enable caching for a request, set a TTL header:

await client.get(
    "https://example.com/data",
    headers={"X-Cache-TTL": "30"},
)

Notes:

  • Cache key = method + URL
  • TTL is read from X-Cache-TTL header
  • Cached responses are fully reconstructed Response objects

Configuration parameters

AioHTTPXClient(...) supports all standard httpx.AsyncClient arguments plus:

Parameter Type Description
redis_url str | None Redis connection URL
key str | None Rate limit Redis key
limit int | None Requests per minute
logger str | None Logger name

Notes & limitations

  • Sync client is not supported
  • HTTP/2 disabled (http1=True, http2=False)
  • Automatic retry on network/connect errors

Requirements

Requires Python: >=3.13
Details
PyPI
2026-01-16 09:46:33 +03:00
34
Miwory
14 KiB
Assets (2)
Versions (2) View all
1.4.0 2026-01-16
1.3.1 2025-12-10