Skip to main content

Aio Adaptive

The goal is to enable an http adaptive rate limit library for python. Project is based off of Netflix Concurrency, but for python! This library is currently only useful in asyncio setup. The initial setup allows for someone to configure the Vegas adaptive rate limit.

The library will automatically limit the outbound requests wrapped in client.use() context manager. Within that manager it utilizes an async semaphore to limit the amount of concurrent calls for this client.

See the examples below for how to leverage it.

Install

You can install aioadaptive using pip:

pip install aioadaptive

Or, if you use uv:

uv add aioadaptive

How to Use

Client Setup

from aioadaptive import AdaptiveClient, AdaptiveClientConfig
from aioadaptive.limiter import VegasLimiter

# Default configuration is to use `vegas` algorithm
client = AdaptiveClient()
# Same as doing
client = AdaptiveClient(AdaptiveClientConfig(algorithm="vegas"))
# Which is also the same as doing
client = AdaptiveClient(AdaptiveClientConfig(algorithm=VegasLimiter()))


async def main():
   # Use the `client` wherever you want to have a persistent rate limit
   async with client.use():
      # Do something with adaptive rate limiting client
      pass


asyncio.run(main())

I.e. Multiple endpoint setup

from aioadaptive import AdaptiveClient, AdaptiveClientConfig
from aioadaptive.limiter import VegasLimiter

# Create a client per API or endpoint. Anything within the `client.use` will be concurrently rate limited within `async with` block.
client1 = AdaptiveClient()
client2 = AdaptiveClient()

async def main():
   async with client1.use():
      # Make some http calls to endpoint 1
      # Will rate limit adaptively based on the latency
      ...
   async with client2.use():
      # Make some http calls to endpoint 2
      # Will rate limit adaptively based on the latency
      ...


asyncio.run(main())

With aiohttp (async)

Note Keep in mind that aiohttp has default a limit connections per host of 100.

import aiohttp
from aioadaptive import AdaptiveClient
import asyncio

client = AdaptiveClient()

async def main():
   async with aiohttp.ClientSession() as session:
      async with client.use():
         async with session.get("https://example.com/") as resp:
            data = await resp.json()
            print(data)

asyncio.run(main())

With httpx (async)

import httpx
from aioadaptive import AdaptiveClient
import asyncio

client = AdaptiveClient()

async def main():
   async with httpx.AsyncClient() as session:
      async with client.use():
         resp = await session.get("https://example.com/")
         print(resp.json())

asyncio.run(main())

With requests (sync, not recommended for adaptive concurrency)

Note: requests is synchronous and blocking, so you won't get the full benefit of adaptive concurrency and is therefore not supported

Developer Setup

  1. Navigate to the Server Directory

    cd aioadaptive
    
  2. Install Server Requirements

    uv venv .venv
    source .venv/bin/activate
    uv sync
    

Development Testing

To run the full test suite (includes integration tests which can be slower)

pytest

Exclude integration tests

pytest -m "not integration"

Metadata

Release files for aioadaptive 0.1.5

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

Source distribution (sdist)

Source distribution for aioadaptive 0.1.5
File Size Uploaded Provenance Actions
aioadaptive-0.1.5.tar.gz 70.4 kB Without provenance Details for aioadaptive-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aioadaptive 0.1.5
File Interpreter ABI Platform Actions
aioadaptive-0.1.5-py3-none-any.whl Python 3 none any Details for aioadaptive-0.1.5-py3-none-any.whl

Total release size: 76.9 kB

Release files / aioadaptive-0.1.5.tar.gz

Download URL aioadaptive-0.1.5.tar.gz
Size 70.4 kB
Tags Source
SHA-256 checksum
How to use checksums
343b30920ef1d45d029a0a88189b0094d49f02b53cc64bf97e95c4593ac13f9e
BLAKE2b-256 checksum
How to use checksums
bda6cf50b60ae2a7f9369b5aead78f26ab33e901c099258d5d33a68b39cd589c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.1

Release files / aioadaptive-0.1.5-py3-none-any.whl

Download URL aioadaptive-0.1.5-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2117ea311f6299244388a691e9f0d978a6a1f23c9f61ed23e090428bbd99ef8f
BLAKE2b-256 checksum
How to use checksums
b35750e640d249b0d9f2125245d4eb10c7e9b627ac9460ce48c5579f66c81634
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.1

Security for aioadaptive 0.1.5

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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