Skip to main content

Async concurrency and queue limiter with server-style backlog control.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async_backlog_limiter-0.1.2.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

async_backlog_limiter-0.1.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file async_backlog_limiter-0.1.2.tar.gz.

File metadata

  • Download URL: async_backlog_limiter-0.1.2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.10 Linux/6.11.0-1014-azure

File hashes

Hashes for async_backlog_limiter-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b59f7e1354be43dfc48d3ab113188f2edb0f3e5a886c3f12ad94e9095126c99c
MD5 9e17fe1bcbf6747d4d929ea3ba016eff
BLAKE2b-256 8ce1e5e3d365000b9fb0e3d12fad3cf08bb7f7b3b53ae8b7e534e05247dd4d0e

See more details on using hashes here.

File details

Details for the file async_backlog_limiter-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for async_backlog_limiter-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fa9dbe1d57658ab60025e0f7b9dbb836c86037ff041fbba1a34abefe830130d8
MD5 898b9ad75dfd647e8e30107b5a847940
BLAKE2b-256 f88122f7f90ae02bcf36c0825963e00f7895c006a3b06d7bd183742941ce8965

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page