throttle - decorator¶
LimitRule
¶
Represents a single rate limiting rule.
Contains the conditions and parameters for a rate limit: - Maximum requests allowed - Time interval - Unique identifier - HTTP methods (optional) - User scopes (optional)
PARAMETER | DESCRIPTION |
---|---|
max_requests
|
Maximum number of requests allowed
TYPE:
|
interval
|
Time interval in seconds
TYPE:
|
throttle_key
|
Unique identifier for this rule
TYPE:
|
method
|
List of HTTP methods this rule applies to
TYPE:
|
scopes
|
List of user scopes this rule applies to
TYPE:
|
Source code in webtool/throttle/decorator.py
for_user
instance-attribute
¶
for_anno
instance-attribute
¶
is_enabled
¶
Checks if this rule should be applied based on request context.
PARAMETER | DESCRIPTION |
---|---|
scope
|
ASGI request scope
TYPE:
|
is_user
|
True if user, False unauthorized
TYPE:
|
auth_data
|
webtool.auth.models.AuthData
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
indicating if rule should be applied
TYPE:
|
Source code in webtool/throttle/decorator.py
LimitRuleManager
¶
Container class for managing multiple rate limit rules. Allows adding and checking rules for specific requests.
Source code in webtool/throttle/decorator.py
should_limit
¶
Determines which rules should be applied for a given request.
PARAMETER | DESCRIPTION |
---|---|
scope
|
ASGI request scope
TYPE:
|
is_user
|
True if user, False unauthorized
TYPE:
|
auth_data
|
webtool.auth.models.AuthData
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[LimitRule]
|
List of applicable rules |
Source code in webtool/throttle/decorator.py
limiter
¶
Decorator for implementing rate limiting on functions.
PARAMETER | DESCRIPTION |
---|---|
max_requests
|
Maximum number of requests allowed in the interval.
TYPE:
|
interval
|
Time interval in seconds (default: 3600)
TYPE:
|
throttle_key
|
Custom key for the rate limit (default: function path)
TYPE:
|
method
|
List of HTTP methods to apply limit to (optional)
TYPE:
|
scopes
|
List of user scopes to apply limit to (optional)
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable
|
Decorated function with rate limiting rules
TYPE:
|