{"id":20733134,"url":"https://github.com/ping/gae-django-ratelimiter","last_synced_at":"2025-12-24T07:34:25.400Z","repository":{"id":85767084,"uuid":"116122255","full_name":"ping/gae-django-ratelimiter","owner":"ping","description":"A Just Good Enough™ Django request rate limiter for use on Google App Engine (GAE).","archived":false,"fork":false,"pushed_at":"2018-07-31T02:46:00.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T10:45:32.735Z","etag":null,"topics":["django","google-appengine","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ping.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-03T10:07:21.000Z","updated_at":"2022-09-16T19:19:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"f72fe69d-3703-40c0-9fb6-794ad947ccf8","html_url":"https://github.com/ping/gae-django-ratelimiter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ping/gae-django-ratelimiter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ping%2Fgae-django-ratelimiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ping%2Fgae-django-ratelimiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ping%2Fgae-django-ratelimiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ping%2Fgae-django-ratelimiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ping","download_url":"https://codeload.github.com/ping/gae-django-ratelimiter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ping%2Fgae-django-ratelimiter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27997423,"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","status":"online","status_checked_at":"2025-12-24T02:00:07.193Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["django","google-appengine","python"],"created_at":"2024-11-17T05:23:40.510Z","updated_at":"2025-12-24T07:34:25.380Z","avatar_url":"https://github.com/ping.png","language":"Python","readme":"# gae-django-ratelimiter\n\nA basic Django request rate limiter (X requests per Y minutes) for use on Google App Engine (GAE).\n\nJust Good Enough™ for weekend projects.\n\n[![Build](https://img.shields.io/travis/ping/gae-django-ratelimiter.svg)](https://travis-ci.org/ping/gae-django-ratelimiter)\n[![Coverage](https://img.shields.io/coveralls/ping/gae-django-ratelimiter.svg)](https://coveralls.io/github/ping/gae-django-ratelimiter)\n\n## Features\n\n1. Available as middleware ``gae_django_ratelimiter.RateLimiterMiddleware`` or request decorator ``@ratelimit``\n1. Does not limit GAE tasks by default\n1. Does not do much else\n\nCompatible with Django versions \u003e=1.4, \u003c=1.11\n\n## Usage\n\n### Basic\n\n1. Add the ``gae_django_ratelimiter`` folder to your project path\n\n1. Use either the decorator for individual views OR include it in your ``INSTALLED_APPS`` and ``MIDDLEWARE_CLASSES`` (Django\u003c=1.9) or ``MIDDLEWARE`` (Django\u003e=1.10) in your app's  ``settings.py`` to apply it globally.\n\n```python\n# views.py\nfrom gae_django_ratelimiter import ratelimit\n\n@ratelimit(requests=30, minutes=2)\ndef a_view(request):\n    # ...\n```\n\n```python\n# settings.py\n\n# Custom Configuration\nGAE_DJANGO_RATELIMITER_ENABLED = True\nGAE_DJANGO_RATELIMITER_CACHE_PREFIX = 'lolcat'\nGAE_DJANGO_RATELIMITER_CACHE_MINUTES = 2\nGAE_DJANGO_RATELIMITER_CACHE_REQUESTS = 30\n\n# For Django \u003c= 1.9. For newer versions set MIDDLEWARE instead\n# Take care to insert it after SessionMiddleware and AuthenticationMiddleware\nMIDDLEWARE_CLASSES = (\n    'django.middleware.common.CommonMiddleware',\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    # ...\n    'gae_django_ratelimiter.RateLimiterMiddleware',\n    # ...\n)\n\n# ...\n\nINSTALLED_APPS = (\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.sites',\n    'django.contrib.messages',\n    # ...\n    'gae_django_ratelimiter',\n    # ...\n)\n```\n\n### Settings\n\n- ``GAE_DJANGO_RATELIMITER_ENABLED``\n  - Enables rate limiting. Default ``True``.\n- ``GAE_DJANGO_RATELIMITER_CACHE_PREFIX``\n  - Memcache key prefix. Default ``gaerl``.\n- ``GAE_DJANGO_RATELIMITER_CACHE_MINUTES``\n  - Interval in minutes. Default ``2``.\n- ``GAE_DJANGO_RATELIMITER_CACHE_REQUESTS``\n  - Requests per interval. Default ``20``.\n- ``GAE_DJANGO_RATELIMITER_COOLDOWN_LAST_REQ``\n  - The backoff interval starts from the more recent request after throttling has kicked in. Default ``False``.\n- ``GAE_DJANGO_RATELIMITER_COOLDOWN_MINUTES``\n  - The backoff interval in minutes if ``GAE_DJANGO_RATELIMITER_COOLDOWN_LAST_REQ`` is True. Equal to ``GAE_DJANGO_RATELIMITER_CACHE_MINUTES`` by default.\n- ``GAE_DJANGO_RATELIMITER_INCLUDE_URL_NAMES``\n  - List of url names to include. If defined, any url names not in list will be excluded. Default ``[]``.\n- ``GAE_DJANGO_RATELIMITER_EXCLUDE_URL_NAMES``\n  - List of url names to exclude. If defined, any url names not in list will be included. Default ``[]``.\n- ``GAE_DJANGO_RATELIMITER_EXCLUDE_AUTHENTICATED``\n  - Exclude authenticated users from limiting. Default ``True``.\n- ``GAE_DJANGO_RATELIMITER_EXCLUDE_ADMINS``\n  - Exclude admin users from limiting. Default ``True``.\n\n\n### Advance\n\nYou can subclass the decorator or middleware for your own custom logic.\nIf using your own middleware, remember to add your own middleware class instead.\n\n#### Example: Rate limit a crawler bot without affecting other users\n\n```python\n# myratelimiter.py\nimport re\nimport logging\nfrom gae_django_ratelimiter import ratelimit, RateLimiterMiddleware\n\n\nOFFENDING_UA_RE = re.compile(r'^BadBot')\n\n# Use either a Decorator or Middleware\n\n# Decorator\nclass myratelimit(ratelimit):\n\n    def should_ratelimit(self, request):\n        if not super(myratelimit, self).should_ratelimit(request):\n            return False\n\n        ua = request.META.get('HTTP_USER_AGENT', '')\n        return OFFENDING_UA_RE.search(ua)\n\n    def disallowed(self, request):\n        logging.warn('Too many requests from {}'.format(\n            request.META.get('REMOTE_ADDR', ''),\n        )\n        return super(myratelimit, self).disallowed(request)\n\n\n# Middleware\nclass MyRateLimiterMiddleware(RateLimiterMiddleware):\n\n    def should_ratelimit(self, request):\n        if not super(MyRateLimiterMiddleware, self).should_ratelimit(request):\n            return False\n\n        ua = request.META.get('HTTP_USER_AGENT', '')\n        return OFFENDING_UA_RE.search(ua)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fping%2Fgae-django-ratelimiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fping%2Fgae-django-ratelimiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fping%2Fgae-django-ratelimiter/lists"}