MULTIRATE THROTTLING
This module provides a multirate parent throttle for Django Rest Framework (DRF) with optional support for Constance.
The multirate settings prevents from adding several throttle classes for each rate when the scope could be the same.
The use of Constance allows the dynamic change of the throttling rates on the fly.
It supports the use of a white list of IP addresses that are not subject to the throttle.
Dependencies
- Django
- Django Rest Framework
- Constance (Optionally)
Installation
pip install multirate-throttling
Usage
The list of rates for a scope can we defined as a comma-separated list of rates.
A single rate can be defined as a "number/time_unit" where 'number' if the maximum number of requests in the specified 'unit time': 5/day
The unit time can be one of the following: sec, min, hour, day, week. Actually, only the first letter of the unit matters, so you can also use: s, m, h, d, w
Example of a valid list of rates for a scope: "15/s, 20/day, 50/we"
NOTES:
- Should a time unit be repeated, only the last occurrence would be applied.
- Should a rate in the list be wrong, that rate will be ignored and its value logged.
Settings
You can store each scope's settings in two places:
- As a standard DRF throttle, adding the scope and rate list to the 'DEFAULT_THROTTLE_RATES' key of 'REST_FRAMEWORK' in Django settings
- In Constance, prepending 'THROTTLE_RATE_' to the scope's name in UPPER CASE and adding it to the Constance config as a key with the rate list as its value. Later, you will be able to change the rate list on the fly at any time.
As the usage of Constance is optional, you must add the following variable to Django Settings to enable it:
MULTIRATE_THROTTLING_USE_CONSTANCE = True
Examples
- As a DRF standard throttle setting:
REST_FRAMEWORK = {
'THROTTLE_RATE_WHITE_LIST': ['127.0.0.1', ],
'DEFAULT_THROTTLE_RATES': {
'some_scope': '5/sec, 50/min, 100/hour, 500/day, 100/week',
}
}
- As a Constance config:
MULTIRATE_THROTTLING_USE_CONSTANCE = True
CONSTANCE_CONFIG = {
'THROTTLE_RATE_WHITE_LIST': '127.0.0.1, 127.0.0.2',
'THROTTLE_RATE_SOME_SCOPE': '5/sec, 50/min, 100/hour, 500/day, 100/week',
}
Metadata
Release files for multirate-throttling 0.1.3
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 | |
|---|---|---|---|---|
| multirate_throttling-0.1.3.tar.gz | 7.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| multirate_throttling-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.0 kB
Release files / multirate_throttling-0.1.3.tar.gz
| Download URL | multirate_throttling-0.1.3.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1df077f849084fdc2f2a4040223706fea68c84a637940c93a15aad375e36fa13
|
|
BLAKE2b-256 checksum How to use checksums |
f58808de9c24c04042c8955b872a962c672455f14bc38a10befd919de163b265
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Release files / multirate_throttling-0.1.3-py3-none-any.whl
| Download URL | multirate_throttling-0.1.3-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3aa369b68585d346f2fa96a846b599fc9246e04800025a7dcc6a879ee392af27
|
|
BLAKE2b-256 checksum How to use checksums |
fd0b99542290717af595af3da11ccd4e4e480dd17e667c5186751406588d79ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Security for multirate-throttling 0.1.3
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.