{ "info": { "author": "Igor", "author_email": "lilo.panic@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "Intended Audience :: Information Technology", "Intended Audience :: System Administrators", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP :: Dynamic Content :: Page Counters", "Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware", "Topic :: Security", "Topic :: Utilities" ], "description": "``django-throttling`` is a an attempt at creating a simple app that allows to apply \nfrequency limits to user's requests.\n\nFeatures\n========\n\n* per-view maintenance mode\n* per-view timeouts\n* view disabling\n* timeouts are configured with respect to ``request.method``\n* redirects\n* custom congestion views\n* view timeouts support callbacks\n\nRequirements\n============\n\n* django cache\n\nInstallation\n============\n\nDownload ``django-throttling`` using *one* of the following methods:\n\npip\n---\n\n pip install django-throttling\n\nCheckout from GitHub\n--------------------\n\nUse one of the following commands::\n\n git clone http://github.com/night-crawler/django-throttling.git\n\n\nConfiguration\n=============\n\nAdd 'django_throttling' into ``INSTALLED_APPS`` in\n``settings.py``::\n\n INSTALLED_APPS = (\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.sites',\n ...\n 'django_throttling',\n ...\n )\n\n\nMIDDLEWARE\n----------\n\nAdd ``django_throttling.middleware.ThrottleMiddleware`` to your\n``MIDDLEWARE_CLASSES`` in ``settings.py``. You may need 'request.user'\nor 'request.session', etc., so insert it in a right place according to\nyour needs.\n\n\nSETTINGS\n--------\n\n* ``DJANGO_THROTTLING_ENABLED``: enables 'django-throttling'. Default is ``False``.\n* ``DJANGO_THROTTLING_CACHE_EXPIRE``: how long should we keep last_access time.\n If you set a large timeout for view, i.e. 24h, make sure that \n ``DJANGO_THROTTLING_CACHE_EXPIRE`` is not less than your timeout.\n Default is ``60*60``\n* ``DJANGO_THROTTLING_CACHE_PREFIX``: a cache prefix for keys. Default is\n ``THROTTLING``\n* ``THROTTLING_CACHE_KEY_PATTERNS``: a dict with patterns for building the cache\n keys. May be redefined in app settings. Defaults are:\n\n * ``view_method``: cache key pattern for a view with a method specified. \n Default pattern: ``%(prefix)s:%(view)s:%(uid)s:%(ip)s:%(method)s``\n * ``view``: cache key pattern for a view. Default pattern:\n ``%(prefix)s:%(view)s:%(uid)s:%(ip)s``\n * ``site_method``: cache key pattern for a whole site with a method.\n Default pattern: ``%(prefix)s:%(uid)s:%(ip)s:%(method)s``\n * ``site``: a global pattern. Default: ``%(prefix)s:%(uid)s:%(ip)s``\n\n* ``DJANGO_THROTTLING_IGNORE_ADMINS``: ignore throttling if user is admin.\n Default is ``True``.\n* ``DJANGO_THROTTLING``: a dict with app-path keys that configures the limits.\n I.e.:\n ``{'django.contrib.admin.options.change_view': {'all': 50, 'post': 5000}}``\n\nSee Usage. For more.\n\nUsage\n=====\n\nGlobal fall-backs\n-----------------\n\nFall-back timeouts setup for any request at the current site::\n\n DJANGO_THROTTLING = {\n 'all': 1000, \n 'post': 10000,\n 'congestion': 'forum.views.congestion',\n }\n\n\nThat stands for \"one request per second, one POST request per 10s\".\n``congestion`` is a view called after the throttle check, if it failes.\nIt may be a ``uri``, i.e. ``/forum/congestion/``. Must uri start with '/'.\n\nThe simplest congestion view may look like::\n\n def congestion(request, congestion_bundle):\n user = request.user\n progress = int(float(congestion_bundle['delta']) / congestion_bundle['timeout'] * 100)\n c = Context({'user': user, 'congestion_bundle': congestion_bundle, 'progress': progress})\n return render_to_response(get_theme_template(user, 'congestion.html'), c,\n context_instance=RequestContext(request)\n )\n\n\n``congestion_bundle`` is a dict, populated from a ``process_request()``::\n\n congestion_bundle = {\n 'view_func': self.view_func,\n 'view_args': self.view_args,\n 'view_kwargs': self.view_kwargs,\n 'timeout': timeout,\n 'delta': delta,\n }\n\n\nYou may disable all ``POST``'s on your site ('maintenance mode')::\n\n DJANGO_THROTTLING = {\n 'all': 1000,\n 'post': False,\n 'congestion': 'forum.views.congestion',\n }\n\nIn that case you will get `HttpResponseBadRequest()` on any POST.\n\n\nAlso, you may redirect your's `POST` users to an any page::\n\n DJANGO_THROTTLING = {\n 'all': 1000,\n 'post': '/',\n 'congestion': 'forum.views.congestion',\n }\n\n\nor you can use a custom maintenance view for it::\n\n\n DJANGO_THROTTLING = {\n 'all': 1000,\n 'post': 'forum.views.maintenance',\n 'congestion': 'forum.views.congestion',\n }\n\nMaintenance view may look like::\n\n def maintenance(request, maintenance_bundle):\n return HttpPreResponse(maintenance_bundle)\n\n\n\nIf you need a special cache key builder, or just to set a timeout is not enough\nfor you, you can use a callback for, i.e., `POST`, that have to make it's\nchecks and return a tuple of cache key and one of the supported timeout types::\n\n DJANGO_THROTTLING = {\n 'all': 1000,\n 'post': 'callable:helpers.trash.my_callback',\n 'congestion': 'forum.views.congestion',\n }\n\n\nAnd here's the example callback::\n\n def my_callback(request, view_func, view_args, view_kwargs):\n return 'some_strange_key_123', 10000\n\nThe full set of arguments the original view had is provided.\n\n\nAnd don't forget, that it is a *fallback* section, that used *ONLY* if\nyou have no detailed rule for view throttling.\n\n\nPer-view throttling\n-------------------\n\nPer-view throttling is almost the same::\n\n DJANGO_THROTTLING = {\n 'all': 1000,\n 'post': 'callable:helpers.trash.my_callback',\n 'congestion': 'forum.views.congestion',\n\n 'django.contrib.admin.options.change_view': {\n 'post': False, \n 'all': 0,\n 'uri': '/admin/forum/post/23/',\n # 'post': 'callable:helpers.trash.my_callback',\n # 'all': 4000, \n },\n }\n\n\nFirst, it will disable all limits for `django.contrib.admin.options.change_view`.\nThen, it will disable the ``POST`` method for this view, **ONLY** if the\n``request.path`` starts with '/admin/forum/post/23/'. Other options from\nglobal setup are permitted.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/night-crawler/django-throttling", "keywords": "django,throttling", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "django-throttling", "package_url": "https://pypi.org/project/django-throttling/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-throttling/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/night-crawler/django-throttling" }, "release_url": "https://pypi.org/project/django-throttling/0.0.1/", "requires_dist": null, "requires_python": null, "summary": "Basic throttling app for Django", "version": "0.0.1" }, "last_serial": 838457, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "d95aef1575206f517c220e44fe28ec7e", "sha256": "426e63b1f670b2755a27d89a22696cd78947aba190648f747ee9c1dda8ad83b2" }, "downloads": -1, "filename": "django-throttling-0.0.1.tar.gz", "has_sig": false, "md5_digest": "d95aef1575206f517c220e44fe28ec7e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7413, "upload_time": "2013-08-12T18:58:38", "url": "https://files.pythonhosted.org/packages/45/36/ffa1efc92bf975241ed1d3b8b5a5ae1817b1900224d038bdeb506eff4600/django-throttling-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d95aef1575206f517c220e44fe28ec7e", "sha256": "426e63b1f670b2755a27d89a22696cd78947aba190648f747ee9c1dda8ad83b2" }, "downloads": -1, "filename": "django-throttling-0.0.1.tar.gz", "has_sig": false, "md5_digest": "d95aef1575206f517c220e44fe28ec7e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7413, "upload_time": "2013-08-12T18:58:38", "url": "https://files.pythonhosted.org/packages/45/36/ffa1efc92bf975241ed1d3b8b5a5ae1817b1900224d038bdeb506eff4600/django-throttling-0.0.1.tar.gz" } ] }