django-rated


Namedjango-rated JSON
Version 2.0.0 PyPI version JSON
download
home_page
SummaryA rate limiting decorator for Django
upload_time2023-08-22 01:59:33
maintainer
docs_urlNone
author
requires_python
licenseCopyright (c) 2012-2013, Curtis Maloney and individual contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 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. * The name of the copyright holder(s) may not 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 HOLDER 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.
keywords django api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            django-rated
============
[![Downloads](https://pypip.in/d/django-rated/badge.png)](https://crate.io/package/django-rated)
[![Version](https://pypip.in/v/django-rated/badge.png)](https://crate.io/package/django-rated)
[![Build Status](https://secure.travis-ci.org/funkybob/django-rated.png?branch=master)](http://travis-ci.org/funkybob/django-rated)


A rate limiting decorators for Django

Introduction
============

`rated`` allows you to limit request rates a single client may attempt on views in 'realms' of your site.

You control which views are in which 'realm' by either decorating the view, or adding the url pattern into the realm map.

`rated` will keep track of how many requests, and when, a client has made and, if they've exceeded their limit, will return a configurable response -- `503 - Service Unavailable` by default.

Installing
==========

Decorate your views:

```py
@rate_limit('myrealm')
def myview(request):
```

Configuring
===========

Next, configure your realms.

This is done by defining them in the RATED_REALMS setting.  This is a dict where the keys are realm names, and the values are dicts of configs.

A realm config may contain any of the following keys.  Any omitted fall back to the defaults from the settings below.

    allowed:  A list of IPs to exclude from rate limiting.
    duration:   Time after which any requests are forgotten
    limit:      Number of requests before limiting is applied.
    code:       HTTP Status code to use when limiting is applied.
    message:    Response content to return when limiting is applied.

If you're planning to put all limited views into the one realm, you don't need to define RATED_REALMS - the defaults will be used instead.

Assign Realms
=============

There are three ways to apply rate limits.  Either decorate the view directly, add a realm with the same url pattern name, or map the url pattern name to a realm.

You can add mark a view as in the default realm simply:

```py
from rated.decorators import rate_limit

@rate_limit
def myview(...)
```

To add it to a specific realm:

```py
@rated_realm(realm='other')
def myview(...)
```

Otherwise, if the url pattern is named, and the name matches a realm name, it will be considered part of that realm.  There is also the RATED_REALM_MAP, which will map url pattern names to realm names.  The url pattern name is always mapped through here.

Settings
========

RATED_DEFAULT_TIMEOUT:

    How long an access history persists with no accesses.
    Default: 1 hour

RATED_DEFAULT_LIMIT:

    Limit of how many requests an individual client is permitted per hour.
    Default: 100

RATED_RESPONSE_CODE:

    HTTP Status code to return when a request is limited.
    Default: 429

RATED_RESPONSE_MESSAGE:

    Content to include in response when a request is limited.
    Default: ''

RATED_REALMS:

    A dict of config dicts.
    The keys are realm names.
    The values are dicts containing overrides for 'limit', 'timeout' and 'allowed'.
    Default: {}

RATED_REDIS:

    Redis config settings.
    These will be passed directly to create a redis.ConnectionPool instance.

RATED_DEFAULT_ALLOWED:

    A list of IPs which are exempt from rate limiting.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "django-rated",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "django,api",
    "author": "",
    "author_email": "Curtis Maloney <curtis@tinbrain.net>",
    "download_url": "https://files.pythonhosted.org/packages/41/26/9aa620686af177e455cf9b9afa519c2d85e43749462da049f5f54ebacbde/django-rated-2.0.0.tar.gz",
    "platform": null,
    "description": "django-rated\n============\n[![Downloads](https://pypip.in/d/django-rated/badge.png)](https://crate.io/package/django-rated)\n[![Version](https://pypip.in/v/django-rated/badge.png)](https://crate.io/package/django-rated)\n[![Build Status](https://secure.travis-ci.org/funkybob/django-rated.png?branch=master)](http://travis-ci.org/funkybob/django-rated)\n\n\nA rate limiting decorators for Django\n\nIntroduction\n============\n\n`rated`` allows you to limit request rates a single client may attempt on views in 'realms' of your site.\n\nYou control which views are in which 'realm' by either decorating the view, or adding the url pattern into the realm map.\n\n`rated` will keep track of how many requests, and when, a client has made and, if they've exceeded their limit, will return a configurable response -- `503 - Service Unavailable` by default.\n\nInstalling\n==========\n\nDecorate your views:\n\n```py\n@rate_limit('myrealm')\ndef myview(request):\n```\n\nConfiguring\n===========\n\nNext, configure your realms.\n\nThis is done by defining them in the RATED_REALMS setting.  This is a dict where the keys are realm names, and the values are dicts of configs.\n\nA realm config may contain any of the following keys.  Any omitted fall back to the defaults from the settings below.\n\n    allowed:  A list of IPs to exclude from rate limiting.\n    duration:   Time after which any requests are forgotten\n    limit:      Number of requests before limiting is applied.\n    code:       HTTP Status code to use when limiting is applied.\n    message:    Response content to return when limiting is applied.\n\nIf you're planning to put all limited views into the one realm, you don't need to define RATED_REALMS - the defaults will be used instead.\n\nAssign Realms\n=============\n\nThere are three ways to apply rate limits.  Either decorate the view directly, add a realm with the same url pattern name, or map the url pattern name to a realm.\n\nYou can add mark a view as in the default realm simply:\n\n```py\nfrom rated.decorators import rate_limit\n\n@rate_limit\ndef myview(...)\n```\n\nTo add it to a specific realm:\n\n```py\n@rated_realm(realm='other')\ndef myview(...)\n```\n\nOtherwise, if the url pattern is named, and the name matches a realm name, it will be considered part of that realm.  There is also the RATED_REALM_MAP, which will map url pattern names to realm names.  The url pattern name is always mapped through here.\n\nSettings\n========\n\nRATED_DEFAULT_TIMEOUT:\n\n    How long an access history persists with no accesses.\n    Default: 1 hour\n\nRATED_DEFAULT_LIMIT:\n\n    Limit of how many requests an individual client is permitted per hour.\n    Default: 100\n\nRATED_RESPONSE_CODE:\n\n    HTTP Status code to return when a request is limited.\n    Default: 429\n\nRATED_RESPONSE_MESSAGE:\n\n    Content to include in response when a request is limited.\n    Default: ''\n\nRATED_REALMS:\n\n    A dict of config dicts.\n    The keys are realm names.\n    The values are dicts containing overrides for 'limit', 'timeout' and 'allowed'.\n    Default: {}\n\nRATED_REDIS:\n\n    Redis config settings.\n    These will be passed directly to create a redis.ConnectionPool instance.\n\nRATED_DEFAULT_ALLOWED:\n\n    A list of IPs which are exempt from rate limiting.\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2012-2013, Curtis Maloney and individual contributors. All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  * 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.  * The name of the copyright holder(s) may not 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 HOLDER 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. ",
    "summary": "A rate limiting decorator for Django",
    "version": "2.0.0",
    "project_urls": {
        "Repository": "https://github.com/funkybob/django-rated"
    },
    "split_keywords": [
        "django",
        "api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "95c1a94d882ad1567afeb6867179ed5c94bec965d7c9955b07b99b8b85b07f7c",
                "md5": "3d45f56e61969e8d39f283dc30f43a7a",
                "sha256": "a0cfd2a0c0af638e13ee17a77858f61c4940b4b6f111b30783dd63bcc0ff0d44"
            },
            "downloads": -1,
            "filename": "django_rated-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3d45f56e61969e8d39f283dc30f43a7a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6046,
            "upload_time": "2023-08-22T01:59:31",
            "upload_time_iso_8601": "2023-08-22T01:59:31.378096Z",
            "url": "https://files.pythonhosted.org/packages/95/c1/a94d882ad1567afeb6867179ed5c94bec965d7c9955b07b99b8b85b07f7c/django_rated-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "41269aa620686af177e455cf9b9afa519c2d85e43749462da049f5f54ebacbde",
                "md5": "b29e29f9e1f8f1cc3db78e6e7f071e89",
                "sha256": "8a69f9eef2e88dc7f57e942fa8de06a23111dc279f5902cac10b60ccce1ffbe7"
            },
            "downloads": -1,
            "filename": "django-rated-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b29e29f9e1f8f1cc3db78e6e7f071e89",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5345,
            "upload_time": "2023-08-22T01:59:33",
            "upload_time_iso_8601": "2023-08-22T01:59:33.206054Z",
            "url": "https://files.pythonhosted.org/packages/41/26/9aa620686af177e455cf9b9afa519c2d85e43749462da049f5f54ebacbde/django-rated-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-22 01:59:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "funkybob",
    "github_project": "django-rated",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-rated"
}
        
Elapsed time: 0.10254s