Log Rate Limit is a Python library that provides a logging filter for the standard `logging` framework, designed to suppress excessive log output. It works by rate-limiting logs based on configurable streams, preventing log floods. The current version is 1.4.2, released on January 17, 2025, and it appears to be actively maintained. It requires Python versions 3.8.1 or newer, but not Python 4.0.0 or later.
pip install log-rate-limitVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to apply `StreamRateLimitFilter` to a logger, allowing 3 messages per 10 seconds for each unique stream. It shows how the default behavior handles identical messages, how to use a custom `stream_id` to group dynamic messages, and how to explicitly disable rate-limiting for critical logs using `extra=RateLimit(stream_id=None)`.
For dynamic log messages that should be rate-limited together, pass a custom `stream_id` via the `extra` dictionary: `logger.warning('Error: %s', var, extra=RateLimit(stream_id='my_static_error_type'))`.If similar but not identical messages should share a rate limit, provide a consistent `stream_id` for them in the `extra` dictionary: `logger.info('Status update: %s', status, extra=RateLimit(stream_id='status_updates'))`.Ensure your project's Python interpreter is within the `<4.0.0,>=3.8.1` range. Monitor future releases of `log-rate-limit` for Python 4.x compatibility updates if planning to upgrade Python versions.
Identify the static part of your log messages and manually assign a consistent `stream_id` via the `extra=RateLimit()` dictionary for all related log calls. For example, `logger.error("Device %s failed!", device_id, extra=RateLimit(stream_id="device_failure"))`.Adjust the `period_sec` (time window) or `max_logs` (number of allowed logs) parameters when initializing `StreamRateLimitFilter`. Alternatively, for individual critical log messages, explicitly disable rate-limiting by setting `stream_id=None` in the `extra` dictionary: `logger.critical("Emergency!", extra=RateLimit(stream_id=None))`.No dependency data recorded yet.