{"id":15433112,"url":"https://github.com/simonw/ratelimitcache","last_synced_at":"2025-04-14T19:36:15.479Z","repository":{"id":477525,"uuid":"102914","full_name":"simonw/ratelimitcache","owner":"simonw","description":"A memcached backed rate limiting decorator for Django.","archived":false,"fork":false,"pushed_at":"2017-10-12T04:48:52.000Z","size":10,"stargazers_count":142,"open_issues_count":5,"forks_count":19,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-18T07:54:09.524Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://simonwillison.net/2009/Jan/7/ratelimitcache/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonw.png","metadata":{"files":{"readme":"readme.txt","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-01-07T21:36:19.000Z","updated_at":"2024-03-29T19:14:19.000Z","dependencies_parsed_at":"2022-07-08T20:47:11.956Z","dependency_job_id":null,"html_url":"https://github.com/simonw/ratelimitcache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fratelimitcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fratelimitcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fratelimitcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fratelimitcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonw","download_url":"https://codeload.github.com/simonw/ratelimitcache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248946835,"owners_count":21187582,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T18:31:51.588Z","updated_at":"2025-04-14T19:36:15.460Z","avatar_url":"https://github.com/simonw.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"ratelimitcache for Django\n=========================\nBy Simon Willison - http://simonwillison.net/\n\nA rate limiter that uses Django's cache framework, with no requirement for a \npersistent data store.\n\nMore information: http://simonwillison.net/2009/Jan/7/ratelimitcache/\n\nInstallation:\n    \n    Place the ratelimitcache.py on your Python path.\n    \n    Configure your CACHE_BACKEND setting. For best results, use the memcached \n    backend - the other backends do not provide an atomic counter increment \n    and so may suffer from less effective limiting due to race conditions.\n    \n    Cache documentation: http://docs.djangoproject.com/en/dev/topics/cache/\n\nDemo:\n    cd demo/\n    ./manage.py runserver 8008\n    \n    Now browse to:\n        http://localhost:8008/\n        http://localhost:8008/debug/\n        http://localhost:8008/login/\n\nBasic usage (max 20 requests every 3 minutes):\n\n    from ratelimitcache import ratelimit\n    \n    @ratelimit(minutes = 3, requests = 20)\n    def myview(request):\n        # ...\n        return HttpResponse('...')\n\nProtecting a login form, i.e rate limit on IP address and attempted username:\n    \n    from ratelimitcache import ratelimit_post\n    \n    @ratelimit_post(minutes = 3, requests = 10, key_field = 'username')\n    def login(request):\n        # ...\n        return HttpResponse('...')\n\nYou can also use it directly in urls.py. Here's how you would use it with \nthe login() view function provided by Django:\n    \n    from ratelimitcache import ratelimit_post\n    from django.contrib.auth.views import login\n    \n    urlpatterns = patterns('',\n        #...\n        (r'^login/$', ratelimit_post(\n            minutes = 3, requests = 10, key_field = 'username'\n        )(login)),\n    )\n\nCustom behaviour, e.g. logging when the rate limit condition fails:\n    \n    from ratelimitcache import ratelimit\n    from my_logging_app.models import Log\n    import datetime, pprint\n    \n    class ratelimit_with_logging(ratelimit):\n        def disallowed(self, request):\n            Log.objects.create(\n                ip_address = request.META.get('REMOTE_ADDR'),\n                path = request.path,\n                counters = pprint.pformat(\n                    self.get_counters(reqest)\n                ),\n                created = datetime.datetime.now()\n            )\n            return HttpResponseForbidden('Rate limit exceeded')\n    \n    @ratelimit_with_logging(minutes = 3, requests = 20)\n    def myview(request):\n        # ...\n        return HttpResponse('...')\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fratelimitcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonw%2Fratelimitcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fratelimitcache/lists"}