Skip to main content

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',
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(str(e))
return cleaned_data


Project details


Release history Release notifications

This version
History Node

0.1.dev2

History Node

0.1.dev1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django_token_bucket-0.1.dev2-py3-none-any.whl (6.5 kB) Copy SHA256 hash SHA256 Wheel py3 Jul 12, 2018
django_token_bucket-0.1.dev2.tar.gz (3.7 kB) Copy SHA256 hash SHA256 Source None Jul 12, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page