fairdm.api.throttling#

The limits on how often a caller may use the API.

Each kind of caller has two limits, one over a short window to stop a burst and one over a day. Every rate is read from REST_FRAMEWORK["DEFAULT_THROTTLE_RATES"] under the scope named on its class.

Module Contents#

Classes#

AnonBurstThrottle

Limit an anonymous caller over a short window.

AnonDailyThrottle

Limit an anonymous caller over a day.

SignedInThrottle

Count only callers who are signed in, by who they are.

UserBurstThrottle

Limit a signed-in caller over a short window.

UserDailyThrottle

Limit a signed-in caller over a day.

API#

class AnonBurstThrottle[source]#

Bases: rest_framework.throttling.AnonRateThrottle

Limit an anonymous caller over a short window.

Initialization

scope#

‘anon_burst’

class AnonDailyThrottle[source]#

Bases: rest_framework.throttling.AnonRateThrottle

Limit an anonymous caller over a day.

Initialization

scope#

‘anon_day’

class SignedInThrottle[source]#

Bases: rest_framework.throttling.UserRateThrottle

Count only callers who are signed in, by who they are.

Django REST framework’s own class also counts an anonymous caller, by address. The anonymous throttles count those callers, so counting them here would stop them at the signed-in rate whenever it is the lower one.

Initialization

get_cache_key(request, view)[source]#

Return the caller’s key, or none for an anonymous caller.

Args: request: The request being answered. view: The view answering it.

Returns: The cache key counting this person’s requests, or None when the caller is not signed in.

class UserBurstThrottle[source]#

Bases: fairdm.api.throttling.SignedInThrottle

Limit a signed-in caller over a short window.

Initialization

scope#

‘user_burst’

class UserDailyThrottle[source]#

Bases: fairdm.api.throttling.SignedInThrottle

Limit a signed-in caller over a day.

Initialization

scope#

‘user_day’