Skip to main content

No project description provided

Project description

Rate Limiting Decorator

This Python module provides a rate_limit_decorator that allows you to limit the rate at which a function can be called. It supports both synchronous and asynchronous functions, making it versatile for various applications.

Installation

Install the rate-limit-guard package via pip:

pip install rate-limit-guard

Once installed, import rate_limit_decorator into your project and apply it to your functions to enable rate limiting.

Features

  • Rate Limiting: Control the maximum number of function calls within a given time interval.
  • Support for Asynchronous and Synchronous Functions: The decorator works seamlessly with both types of functions.
  • Easy Integration: Simply apply the decorator to your function, and it will handle rate limiting for you.

Usage

Here’s a basic example of how to use the rate_limit_decorator:

Synchronous

from rate_limit_guard import rate_limit_decorator

@rate_limit_decorator(interval=1, max_calls=5)
def my_function():
    print("Function is called")

def main():
    try:
        for _ in range(10):
            my_function()
    except RuntimeError:
        # this will be raised after the rate limit is reached
        pass

Asynchronous

from rate_limit_guard import rate_limit_decorator
import asyncio

@rate_limit_decorator(interval=1, max_calls=5)
async def my_async_function():
    print("Async function is called")
    await asyncio.sleep(0.5)

async def main():
    try:
        for _ in range(10):
            await my_async_function()
    except RuntimeError:
        # this will be raised after the rate limit is reached
        pass

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

rate_limit_guard-0.1.3.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

rate_limit_guard-0.1.3-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file rate_limit_guard-0.1.3.tar.gz.

File metadata

  • Download URL: rate_limit_guard-0.1.3.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.10 Darwin/23.6.0

File hashes

Hashes for rate_limit_guard-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b6484d9391a8481ae0b98395380273ff207f4722f4401dc5428ae47647c45155
MD5 035428dcdf917a6f1cd9731d4eb4e0f0
BLAKE2b-256 822b5eeccaddc789ff1657bfc7bf35957d3e504fdfb1095991484534c1b95852

See more details on using hashes here.

File details

Details for the file rate_limit_guard-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for rate_limit_guard-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 956365ea14b3307e2ae98c2510242f6df5de61a5eb3a1db4a5b0648d87eb438b
MD5 a9770a490b1d71bdae3a08007e6e09d7
BLAKE2b-256 f90fc960b5b33d20ea7bb0eea26a3cb0dc5877e246e9e6e9fe71ba4373fc9c0c

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