Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

Makes it easy to respect rate limits.

Project Description

Ratelim is a simple Python library that limits the number of times a function can be called in during a time interval. It is particularly useful when using o online APIs, which commonly enforce rate limits.

Installation

$ pip install ratelim

Usage

Say you want to call a function at most for n_calls during a n_seconds time interval.

# 10 times in 5 seconds
@ratelim.greedy(10, 5)
def hello(lines):
    print("hello")

The greedy rate limiter calls does not delay any function call until it’s really necessary.

In some scenarios, for example when crawling data from an API, you want to maximize the number of calls you make and you want to avoid sending them in short sequence. For this goal, we can use the patient rate limiter. It distributes calls evenly between each other.

# 10 times in 5 seconds
# Get's called at most every 0.5 seconds
@ratelim.patient(10, 5)
def hello(lines):
    print("hello")

LICENSE

MIT.

History

0.1.0 (2014-12-21)

Initial release.

Release History

Release History

This version
History Node

0.1.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
ratelim-0.1.0.tar.gz (2.4 kB) Copy SHA256 Checksum SHA256 Source Dec 21, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting