Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

API rate limit decorator

Project Description

APIs are a very common way to interact with web services. As the need to consume data grows, so does the number of API calls necessary to remain up to date with data sources. However many API providers constrain developers from making too many API calls. This is know as rate limiting and in a worst case scenario your application can be banned from making further API calls if it abuses these limits.

This packages introduces a method decorator preventing a method from being called more than once within a given time period. This should prevent API providers from banning your applications by conforming to set rate limits.



To install ratelimit, simply:

$ pip install ratelimit


Installing the latest version from Github:

$ git clone
$ cd ratelimit
$ python install


To use this package you simply have to declare the decorator before the method you wish to rate limit:

from ratelimit import rate_limited
import requests

def call_api(self, url):
  response = requests.get(url)

  if response.status_code != 200:
    raise ApiError('Cannot call API: {}'.format(response.status_code))

  return response

This method makes a call to our API. Note that this method has been implemented with a decorator enforcing that it may only be called once per second.

The argument passed into the decorator imposes the number of method invocation allowed over a time period specified (in seconds). If no time period is specified then it default to 1 second.


  1. Fork it (
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am ‘Add some feature’)
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(4.0 kB) Copy SHA256 Hash SHA256
Source None Aug 6, 2017

Supported By

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 Google Google Cloud Servers DreamHost DreamHost Log Hosting