API Reference Guide¶
Limiter¶
Limiter¶
-
class
falcon_limiter.limiter.
Limiter
(key_func: Callable = <function get_remote_addr>, default_limits: str = '', default_deduct_when: Callable = None, default_dynamic_limits: Callable = None, config: Optional[Dict[str, Any]] = None)¶ This is the central class for the limiting
You need to initialize this object to setup the attributes of the Limiter and then supply the object’s middleware to the Falcon app.
Parameters: - key_func (callable) – A function that will receive the usual Falcon request method arguments (req, resp, resource, params) and expected to return a string which will be used as a representation of the user for whom the rate limit will apply (eg the key).
- default_limits (str) – Optional string of limit(s) separated by “;”, like ‘1/second;3 per hour’
- default_deduct_when (callable) – A function which determines at response time whether the given request should be counted against the limit or not. This allows the creation of strategies incorporating the response status code.
- default_dynamic_limits (callable) – A function which builds the ‘limits’ string dynamically based on the Falcon request method arguments (req, resp, resource, params). It is expected to return a ‘limits’ string like ‘1/second;3 per hour’.
- config (dict of str) – Optional config settings provided as a dictionary
-
key_func
¶ A function that will receive the usual Falcon request method arguments (req, resp, resource, params) and expected to return a string which will be used as a representation of the user for whom the rate limit will apply (eg the key).
Type: callable
-
default_deduct_when
¶ A function which determines at response time whether the given request should be counted against the limit or not. This allows the creation of strategies incorporating the response status code.
Type: callable
-
default_dynamic_limits
¶ A function which builds the ‘limits’ string dynamically based on the Falcon request method arguments (req, resp, resource, params). It is expected to return a ‘limits’ string like ‘1/second;3 per hour’.
Type: callable
-
config
¶ Config settings stored as a dictionary
Type: dict of str
-
storage
¶ The storage backend that will be used to store the rate limits.
Type: Storage
-
limiter
¶ A RateLimiter object from the limits library, representing the rate limiting strategy and storage.
Type: RateLimiter
-
limit
(limits: str = None, deduct_when: Callable = None, key_func: Callable = None, dynamic_limits: Callable = None) → Callable¶ This is the decorator used to decorate a resource class or the requested method of the resource class with the default or with a custom limit
Parameters: - limits (str) – Optional string of limit(s) separated by “;”, like ‘1/second;3 per hour’ deduct_when (callable): A function that will receive the usual falcon response method arguments (req, resp, resource, params) and expected to return a boolean which is used to determine if the given response qualifies to count against the set limit.
- deduct_when (callable) – A function which determines at response time whether the given request should be counted against the limit or not. This allows the creation of strategies incorporating the response status code.
- key_func (callable) – A function that will receive the usual falcon response method arguments (req, resp, resource, params) and expected to return a string which will be used as a representation of the user for whom the rate limit will apply (eg the key).
- dynamic_limits (callable) – A function which builds the ‘limits’ string dynamically based on the Falcon request method arguments (req, resp, resource, params). It is expected to return a ‘limits’ string like ‘1/second;3 per hour’.
-
middleware
¶ Falcon middleware integration