betty.http_client.rate_limit module

HTTP client rate limiting.

final class betty.http_client.rate_limit.RateLimitDefinition

Bases: OrderedPluginDefinition

The http client rate limit plugin type. Rate limits ensure that Betty’s HTTP client does not make more requests to a web service than that service supports or allows, by enforcing a maximum number of requests per timeframe.

Plugin type ID

http-rate-limit

Definition

@RateLimitDefinition(...)

Built-in http client rate limits:

__init__(plugin_id: ResolvableMachineName, *, limit: tuple[int, int], match: str | re.Pattern, auto: bool = True, after: Order[RateLimitDefinition] = (), before: Order[RateLimitDefinition] = (), requires: Requires = ())
property limit: tuple[int, int]

The limit expressed as a 2-tuple of the maximum and the period (in seconds).

match(request: ClientRequest, /) bool

Check the rate limit matches the given URL.

static type() PluginTypeDefinition[Self]

The plugin type definition.

final class betty.http_client.rate_limit.RateLimitMiddleware

Bases: object

HTTP client middleware to rate-limit requests.

This is thread-safe, which means you can safely use this between different threads.

__init__(limits: Iterable[RateLimitDefinition], /)