Skip to main content

Advanced rate limiting in Python

Project description

limited 🚀

limited is your go-to Python rate limiting package, designed for advanced and efficient performance. It seamlessly supports both synchronous programs, using threads through SyncLimiter, and asynchronous programs, utilizing asyncio through AsyncLimiter.

Examples 📝

Getting started with limited is effortless! For regular, synchronous functions declared with def, use SyncLimiter:

from limited import SyncLimiter

@SyncLimiter(limit=3, every=5)
def job():
    pass

For asynchronous functions declared with async def, opt for AsyncLimiter:

from limited import AsyncLimiter

@AsyncLimiter(limit=3, every=5)
async def async_job():
    pass

Share Limits 👨‍👦‍👦

Take it up a notch by creating a limiter instance and share it across multiple functions. This allows you to enforce the same constraints on multiple functions simultaneously. In the example below, both first_job and second_job are limited to 3 calls every 5 seconds, collectively.

from limited import SyncLimiter

my_limiter = SyncLimiter(limit=3, every=5)

@my_sync_limiter
def first_job():
    pass

@my_sync_limiter
def second_job():
    pass

For asynchronous functions, employ AsyncLimiter in a similar fashion.

Stack Limits 📚

Stack limits on a single function to satisfy multiple constraints simultaneously. In the following example, both limiting constrained are enforces separately.

from limited import SyncLimiter

my_first_limiter = SyncLimiter(limit=3, every=5)
my_second_limiter = SyncLimiter(limit=1, every=1)

@my_first_limiter
@my_second_limiter
def my_job():
    pass

Combining sharing limits with multiple functions, and stacking multiple limits to the same functions, allows for complex limiting logic.

limited offers the flexibility you need to create complex rate limiting logic effortlessly. Fine-tune your applications, experiment, and let your projects soar to new heights! 🚀✨

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

limited-0.1.0.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

limited-0.1.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file limited-0.1.0.tar.gz.

File metadata

  • Download URL: limited-0.1.0.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for limited-0.1.0.tar.gz
Algorithm Hash digest
SHA256 443668d70fdbdcc791b91962b405018d817198d981d5ad05bd8e44152c14493a
MD5 05046c2cb3739bc538178da355deda98
BLAKE2b-256 9e8f7dc34806595f04ff00a9d5369d14cbd63f7115aefc2c43c01a750146c73f

See more details on using hashes here.

File details

Details for the file limited-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: limited-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for limited-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7dbd5741089943fe1cf470efdb220cda1404e3988b51c0b95cf216fff47b33a
MD5 a4833005215a42100d9f699b93bc4f11
BLAKE2b-256 fd96a2d77cd08d98fb029ad6b824b121a5899d23102b1b50d0de23596e4aaade

See more details on using hashes here.

Supported by

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