Skip to content

aiohttp-client-middlewares

GitHub Actions CI status codecov.io status Latest PyPI package version Supported Python versions Latest Read The Docs

Reusable client middlewares for aiohttp.

aiohttp-client-middlewares is a small, pure-Python collection of ready-to-use client middlewares for aiohttp. It currently provides:

  • DigestAuthMiddleware -- HTTP Digest authentication, vendored from aiohttp core; this package is the canonical home for it going forward.
  • RateLimitMiddleware -- client-side rate limiting with a pluggable algorithm (a token bucket is included) and optional per-domain limiters.

Middlewares plug into aiohttp.ClientSession through the client middleware API introduced in aiohttp 3.12, so they can wrap every outgoing request without subclassing the session.

Installation

$ pip install aiohttp-client-middlewares

This requires aiohttp >= 3.12 (the first release with the client-middleware API and DigestAuthMiddleware) and yarl >= 1.17.0. Both are pulled in automatically.

Supported Python versions: 3.10, 3.11, 3.12, 3.13 and 3.14.

Quickstart

Pass one or more middlewares to aiohttp.ClientSession via the middlewares argument. DigestAuthMiddleware transparently performs the HTTP Digest authentication handshake for every request made with the session:

import asyncio

import aiohttp
from aiohttp_client_middlewares import DigestAuthMiddleware


async def main() -> None:
    digest = DigestAuthMiddleware("user", "pass")
    async with aiohttp.ClientSession(middlewares=(digest,)) as session:
        async with session.get("https://httpbin.org/digest-auth/auth/user/pass") as resp:
            print("Status:", resp.status)
            print("Body:", await resp.json())


asyncio.run(main())

Documentation

https://aiohttp-client-middlewares.readthedocs.io/

Links

Communication channels

aio-libs Discussions: https://github.com/aio-libs/aiohttp-client-middlewares/discussions

Matrix: #aio-libs:matrix.org

License

aiohttp-client-middlewares is offered under the Apache-2.0 license. See the LICENSE file for the full text.

About

A collection of useful client middlewares

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages