Rate Limiter

The synchronous and asynchronous clients create a limiter from their max_requests_per_second and rate_limit_* constructor arguments. Most applications should configure the client instead of constructing this class directly.

Request rate limiting for synchronous and asynchronous S7 clients.

class snap7.rate_limiter.RequestRateLimiter(max_requests_per_second: float = 0, *, algorithm: ~typing.Literal['fixed', 'token_bucket'] = 'fixed', behavior: ~typing.Literal['block', 'raise'] = 'block', burst_capacity: int | None = None, _clock: ~collections.abc.Callable[[], float] = <built-in function monotonic>, _sleep: ~collections.abc.Callable[[float], None] = <built-in function sleep>)[source]

Per-client request rate limiter with thread-safe accounting.

fixed spaces requests evenly. token_bucket permits bursts up to burst_capacity and then refills continuously at the configured rate. A rate of zero disables limiting. This lock protects only limiter state; it does not make the synchronous client safe for concurrent use.

acquire() → None[source]

Wait for or reserve permission to send one synchronous request.

async acquire_async() → None[source]

Wait for or reserve permission to send one asynchronous request.

property enabled: bool

Whether rate limiting is active.