ratelimit
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.
Installation
PyPi
To install ratelimit, simply:
$ pip install ratelimit
GitHub
Installing the latest version from Github:
$ git clone https://github.com/tomasbasham/ratelimit
$ cd ratelimit
$ python setup.py install
Usage
To use this package you simply have to declare the decorator before the method you wish to rate limit:
from ratelimit import *
import requests
@rate_limited(1)
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 that dictates that this method may only be called once per second.
The argument passed into the decorator imposes the time that must elapse before a method can be called again.
Contributing
Fork it ( https://github.com/tomasbasham/ratelimit/fork )
Create your feature branch (git checkout -b my-new-feature)
Commit your changes (git commit -am ‘Add some feature’)
Push to the branch (git push origin my-new-feature)
Create a new Pull Request
Metadata
Release files for ratelimit 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ratelimit-1.1.0.tar.gz | 3.5 kB | Without provenance | Details for ratelimit-1.1.0.tar.gz |
Release files / ratelimit-1.1.0.tar.gz
| Download URL | ratelimit-1.1.0.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a64faacd9ac4a79a3cb274b43e0160c25c96724156f606525ed8d2d924991cf6
|
|
BLAKE2b-256 checksum How to use checksums |
d8863fed15cc23cc139b3f2fd8c92d78c93df70dea10cd7c058758b23c1a2144
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for ratelimit 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.