Throttle API Requests

A snippet showing how to enable API throttling in DRF.


# settings.py

REST_FRAMEWORK = {
    "DEFAULT_THROTTLE_CLASSES": [
        "rest_framework.throttling.AnonRateThrottle",
        "rest_framework.throttling.UserRateThrottle",
    ],
    "DEFAULT_THROTTLE_RATES": {
        "anon": "100/hour",
        "user": "1000/hour",
    },
}
      
Explanation:
  • DRF automatically enforces rate limits per IP/user; 429 is returned when exceeded.
Previous snippet
Versioning APIs
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.