Django Tocken Bucket support.
Project description
# django_token_bucket
A token bucket implementation for Django to implement rate limiting
on individual user actions, for example submitting a form.
example for consuming a token on Form validation:
INVITATION_MAX_TOKENS = 5
INVITATION_FILL_RATE = 300 # a token each x seconds
def clean(self):
cleaned_data = super(InvitationForm, self).clean()
bucket = TokenBucket.get(identifier='invitations_sent',
user=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(e.get_message())
return cleaned_data
A token bucket implementation for Django to implement rate limiting
on individual user actions, for example submitting a form.
example for consuming a token on Form validation:
INVITATION_MAX_TOKENS = 5
INVITATION_FILL_RATE = 300 # a token each x seconds
def clean(self):
cleaned_data = super(InvitationForm, self).clean()
bucket = TokenBucket.get(identifier='invitations_sent',
user=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(e.get_message())
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.1.dev1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b51104e9d3753a94e13e47fcdb8d02e80b1eb7f17d06ae808ffc1cf7ee1a78a9 |
|
MD5 | bd60e5dc945ca3ad296bfde94fa98113 |
|
BLAKE2b-256 | 39759b51f304298dbcb4728e52bab622a9d0df87aaef20cf142d6279f259b455 |
Close
Hashes for django_token_bucket-0.1.dev1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d99885fd0bcdaa427800dae785a676acc1298a4ab59d80cde0499af587948e5f |
|
MD5 | fd395432bca3d4a9dcec5d2ad4eabdc6 |
|
BLAKE2b-256 | ee41f48b0c17ef730f5450b78a4c8c8bd4ac8186cebb9176fbc60d94a5f36b9a |