# -*- coding: utf-8 -*-
from distutils.core import setup

packages = \
['ratelimit']

package_data = \
{'': ['*']}

install_requires = \
['django>=2.0']

setup_kwargs = {
    'name': 'django-fast-ratelimit',
    'version': '0.3.3',
    'description': 'Fast ratelimit implementation with django caches',
    'long_description': '# django-fast-ratelimit\n\n\nDjango-fast-ratelimit provides a secure and fast ratelimit facility based on the django caching framework.\n\n\n## Installation\n\n```` bash\npip install django-fast-ratelimit\n\n````\n\nNote: pip >= 19 is required, I use the novel pyproject.toml method\n\n## usage\n\n\nDecorator:\n\n```` python\nimport ratelimit\n\n@ratelimit.decorate(key="ip", rate="1/s")\ndef expensive_func(request):\n    # how many ratelimits request limiting\n    if request.ratelimit["request_limit"] > 0:\n        # reschedule with end of rate epoch\n        return request_waiting(request.ratelimit["end"])\n\n````\n\nblocking Decorator (raises RatelimitError):\n\n```` python\nimport ratelimit\n\n@ratelimit.decorate(key="ip", rate="1/s", block=True, methods=ratelimit.UNSAFE)\ndef expensive_func(request):\n    # how many ratelimits request limiting\n    if request.ratelimit["end"] > 0:\n\n````\n\n\n\ndecorate View (requires group):\n\n```` python\nimport ratelimit\nfrom django.views.generic import View\nfrom django.utils.decorators import method_decorator\n\n\n@method_decorator(ratelimit.decorate(\n  key="ip", rate="1/s", block=True, methods=ratelimit.SAFE, group="required"\n), name="dispatch")\nclass FooView(View):\n    ...\n\n````\n\nmanual\n```` python\nimport ratelimit\n\n\ndef func(request):\n    ratelimit.get_ratelimit(key="ip", rate="1/s", request=request, group="123")\n    # or only for GET\n    ratelimit.get_ratelimit(\n        key="ip", rate="1/s", request=request, group="123", methods="GET"\n    )\n    # also simple calls possible (note: key in bytes format)\n    ratelimit.get_ratelimit(\n        key=b"abc", rate="1/s", group="123"\n    )\n    # for simple naming use o2g (object to group)\n    ratelimit.get_ratelimit(\n        key=b"abc", rate="1/s", group=ratelimit.o2g(func)\n    )\n\n````\n\n## parameters\n\nratelimit.get_ratelimit:\n\n* group: group name, can be callable (fun(request))\n* methods: set of checked methods, can be callable (fun(request, group)), modes:\n  * callable(request, group): allow dynamic\n  * ratelimit.ALL (default): all methods are checked\n  * \\("HEAD", "GET"\\): list of checked methods\n  * ratelimit.invertedset(["HEAD", "GET"]): inverted set of checked methods. Here: every method is checked, except HEAD, GET\n* request: ingoing request (optional if key supports it and methods=ratelimit.ALL (default))\n* key: multiple modes possible:\n    * str: "path.to.method:argument"\n    * str: "inbuildmethod:argument" see methods for valid arguments\n    * str: "inbuildmethod"  method which is ready to use for (request, group)\n    * tuple,list: ["method", args...]: method (can be also inbuild) with arbitary arguments\n    * bytes: static key (supports no request mode)\n    * callable: check return of function (fun(request, group))\n  * cache: specify cache to use, defaults to RATELIMIT_DEFAULT_CACHE setting (default: "default")\n  * hash_algo: name of hash algorithm for creating cache_key (defaults to RATELIMIT_KEY_HASH setting (default: "sha256"))\n    Note: group is seperately hashed\n  * hashctx: optimation parameter, read the code and only use if you know what you are doing. It basically circumvents the paramater hashing and only hashes the key. If the key parameter is True even the key is skipped\n\nratelimit.decorate:\n\nAll of ratelimit.get_ratelimit except request. group is here optional (except for decorations with method_decorator (no access to wrapped function)).\nAlso supports:\n* block: should hard block with an RatelimitExceeded exception (subclass of PermissionDenied) or only annotate request with ratelimit\n\n\n## TODO\n\n* more documentation\n',
    'author': 'Alexander Kaftan',
    'author_email': None,
    'url': 'https://https://github.com/devkral/django-fast-ratelimit',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.5',
}


setup(**setup_kwargs)
