Django Tocken Bucket support.
Project description
A token bucket implementation for Django to implement rate limiting on individual user actions, for example submitting a form.
Installation ############
Insatall:
pip install django-token-bucket
add it to your installed apps:
INSTALLED_APPS = [
'...',
'django_token_bucket'
]
run migrations:
./manage.py migrate django_token_bucket
Examples ########
example for consuming a token on Form validation:
INVITATION_MAX_TOKENS = 5
INVITATION_FILL_RATE = 300 # a token each 300 seconds
def clean(self):
cleaned_data = super(InvitationForm, self).clean()
bucket = TokenBucket.get(identifier='invitations_sent',
ref_object=self.user,
max_tokens=INVITATION_MAX_TOKENS,
fill_rate=INVITATION_FILL_RATE,
whatfor='invitations')
try:
bucket.consume(1)
except bucket.TokensExceeded as e:
raise forms.ValidationError(str(e))
return cleaned_data
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django_token_bucket-0.2.dev1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f0bc6c8056206bef0e1b0f4d325ffdec2b5a5ef257b345c606777b9892e7e27 |
|
MD5 | 42bf4b4f5c9505fa3efa32fc195aa64c |
|
BLAKE2b-256 | fff6690b3489de18ca1613b697e6280bf3d1c8f67ecb6b586bd116486b203206 |
Close
Hashes for django_token_bucket-0.2.dev1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0c763139e9abab782d1a984f8118155c9c3416c355a0c9d7b1217f6852bac5d |
|
MD5 | d3deae04bfa58672c5a8f1fcd4bbc03d |
|
BLAKE2b-256 | 1dcda856076ecf96e72df34d357bdeae743d3fa8b7aff6e99d7e1e24674c5ead |