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-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7cc5d593180efe4540bc9b43c1d90c63fcf058a4c38be4c1ae7fb4579193f75 |
|
MD5 | 00f7f1969a14c2c417771d7a99dc1f10 |
|
BLAKE2b-256 | 5e0c984d567e9692b1933d6a858eb279d1ff08c9f21353403d063332bfbe10fd |