Throttling (durin.throttling)

Durin provides a throttling class which make use of the durin.models.Client model it offers.

Usage is the same way as other DRF throttling classes.

Example settings.py:

#...snip...
REST_FRAMEWORK = {
    "DEFAULT_THROTTLE_CLASSES": ["durin.throttling.UserClientRateThrottle"],
    "DEFAULT_THROTTLE_RATES": {"user_per_client": "10/min"},
}
#...snip...
"user_per_client"

default scope for the UserClientRateThrottle class.

The rate defined here serves as the default rate incase the throttle_rate field on durin.models.Client is null.


UserClientRateThrottle

class durin.throttling.UserClientRateThrottle[source]

Bases: rest_framework.throttling.UserRateThrottle

Throttles requests by identifying the authed user-client pair.

This is useful if you want to define different user throttle rates per durin.models.Client instance.

New in version 0.2.

allow_request(request, view)[source]

The rate is set here because we need access to request object which is not available inside get_rate().

cache_format = 'throttle_%(scope)s_%(ident)s'

Same as the default

get_cache_key(request, view) → str[source]

Should return a unique cache-key which can be used for throttling. Must be overridden.

May return None if the request should not be throttled.

scope = 'user_per_client'

Scope for this throttle

static validate_client_throttle_rate(rate)[source]

Used for validating the throttle_rate field on durin.models.Client.

For internal use only.