Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add package stuff.

  • Loading branch information...
commit aa5fa7a9185f42bf52865114fb9a6cdcd905ee6b 1 parent c3f2790
James Socol authored
Showing with 126 additions and 0 deletions.
  1. +28 −0 LICENSE
  2. +2 −0  MANIFEST.in
  3. +69 −0 README.rst
  4. +27 −0 setup.py
View
28 LICENSE
@@ -0,0 +1,28 @@
+Copyright (c) 2011, Mozilla Foundation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ 3. Neither the name of django-ratelimit nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
View
2  MANIFEST.in
@@ -0,0 +1,2 @@
+include LICENSE
+include README.rst
View
69 README.rst
@@ -0,0 +1,69 @@
+================
+Django Ratelimit
+================
+
+Django Ratelimit provides a decorator to rate-limit views. Limiting can be
+based on IP address or a field in the request--either a GET or POST variable.
+
+If the rate limit is exceded, either a 403 Forbidden can be sent, or the
+request can be annotated with a ``limited`` attribute, allowing you to take
+another action like adding a captcha to a form.
+
+
+Using Django Ratelimit
+======================
+
+``from ratelimit.decorators import ratelimit`` is the biggest thing you need to
+do. The ``@ratelimit`` decorator provides several optional arguments with
+sensible defaults (in *italics*).
+
+:``ip``:
+ Whether to rate-limit based on the IP. *True*
+:``block``:
+ Whether to block the request instead of annotating. *False*
+:``method``:
+ Which HTTP method(s) to rate-limit. May be a string or a list. *all*
+:``field``:
+ Which HTTP field(s) to use to rate-limit. May be a string or a list. *none*
+:``rate``:
+ The number of requests per unit time allowed. *5/m*
+
+
+Examples
+--------
+
+::
+
+ @ratelimit()
+ def myview(request):
+ # Will be true if the same IP makes more than 5 requests/minute.
+ was_limited = getattr(request, 'limited', False)
+ return HttpResponse()
+
+ @ratelimit(block=True)
+ def myview(request):
+ # If the same IP makes >5 reqs/min, will return HttpResponseForbidden
+ return HttpResponse()
+
+ @ratelimit(field='username')
+ def login(request):
+ # If the same username OR IP is used >5 times/min, this will be True.
+ # The `username` value will come from GET or POST, determined by the
+ # request method.
+ was_limited = getattr(request, 'limited', False)
+ return HttpResponse()
+
+ @ratelimit(method='POST')
+ def login(request):
+ # Only apply rate-limiting to POSTs.
+ return HttpResponseRedirect()
+
+ @ratelimit(field=['username', 'other_field'])
+ def login(request):
+ # Use multiple field values.
+ return HttpResponse()
+
+ @ratelimit(rate='4/h')
+ def slow(request):
+ # Allow 4 reqs/hour.
+ return HttpResponse()
View
27 setup.py
@@ -0,0 +1,27 @@
+from setuptools import setup, find_packages
+
+setup(
+ name='django-ratelimit',
+ version='0.1',
+ description='Cache-based rate-limiting for Django.',
+ long_description=open('README.rst').read(),
+ author='James Socol',
+ author_email='james@mozilla.com',
+ url='http://github.com/jsocol/django-ratelimit',
+ license='BSD',
+ packages=find_packages(),
+ include_package_data=True,
+ package_data = { '': ['README.rst'] },
+ install_requires=['django'],
+ classifiers=[
+ 'Development Status :: 4 - Beta',
+ 'Environment :: Web Environment',
+ 'Environment :: Web Environment :: Mozilla',
+ 'Framework :: Django',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: BSD License',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python',
+ 'Topic :: Software Development :: Libraries :: Python Modules',
+ ]
+)
Please sign in to comment.
Something went wrong with that request. Please try again.