Skip to main content

Async Backlog Limiter

codecov PyPI PyPI - Python Version

A lightweight, zero-dependency Python library to limit concurrent execution and queue size of asynchronous tasks — simulating a TCP-style backlog for async servers, job runners, or microservices to ensure overload protection.

📦 Installation

pip install async-backlog-limiter

🛠️ Usage

  • If more than capacity concurrent requests are running, additional ones will wait.
  • If the total number of active + waiting requests exceeds queue_limit, new ones are immediately rejected with a RateLimitExceeded exception.
import asyncio
from async_backlog_limiter import AsyncBacklogLimiter, RateLimitExceeded

limiter = AsyncBacklogLimiter(capacity=5, queue_limit=10)

async def handle_request():
    try:
        async with limiter():
            # Your async work here
            await asyncio.sleep(1)
    except RateLimitExceeded:
        print("Request rejected due to overload.")

# Run many tasks
await asyncio.gather(*[handle_request() for _ in range(20)])

# Get current statistics about the limiter's state
limiter.stats()

🧪 Tests

This project includes a comprehensive test suite using unittest.

To run tests:

python -m unittest discover -s tests

Metadata

Release files for async-backlog-limiter 0.1.3

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

Source distribution (sdist)

Source distribution for async-backlog-limiter 0.1.3
File Size Uploaded
async_backlog_limiter-0.1.3.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for async-backlog-limiter 0.1.3
File Interpreter ABI Platform
async_backlog_limiter-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.2 kB

Release files / async_backlog_limiter-0.1.3.tar.gz

Download URL async_backlog_limiter-0.1.3.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
90b9840bc33265ddf052c6aa207f9263126a68045f6312e3191636609b8cc870
BLAKE2b-256 checksum
How to use checksums
09ff26ffdd1d7acdb9bdda3818d40eae57112d8f7131a3b3503519c3ae4a391b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.10 Linux/6.11.0-1014-azure

Release files / async_backlog_limiter-0.1.3-py3-none-any.whl

Download URL async_backlog_limiter-0.1.3-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89b1de40288a2ebe1debfb82a7ce3b8e238ea07b5f7bfa64bdd6315002215668
BLAKE2b-256 checksum
How to use checksums
94f4c329571709f8f73d329a26eaca6f1ca23b0320580a11df5c73eb52cf9806
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.10 Linux/6.11.0-1014-azure

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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