{"library":"log-rate-limit","title":"Log Rate Limit","description":"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.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install log-rate-limit"],"cli":null},"imports":["from log_rate_limit import RateLimit","from log_rate_limit import StreamRateLimitFilter"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import logging\nimport time\nfrom log_rate_limit import RateLimit, StreamRateLimitFilter\n\n# Configure basic logging\nlogging.basicConfig(level=logging.INFO, format='%(levelname)s:%(name)s:%(message)s')\nlogger = logging.getLogger(__name__)\n\n# Apply the rate limit filter to the logger\n# This example allows 3 logs per 10 seconds for each unique stream_id\nlogger.addFilter(StreamRateLimitFilter(period_sec=10, max_logs=3))\n\nprint(\"--- Demonstrating default rate limiting (same messages) ---\")\nfor i in range(5):\n    logger.info(\"Repeating message!\")\n    time.sleep(0.5)\n\nprint(\"\\n--- Demonstrating custom stream_id for dynamic messages ---\")\n# Messages with dynamic content can be grouped by a custom stream_id\nfor i in range(5):\n    device_id = \"device_A\"\n    logger.warning(\"Error on %s: process %d failed!\", device_id, i, extra=RateLimit(stream_id=f\"error_on_{device_id}\"))\n    time.sleep(0.5)\n\nprint(\"\\n--- Demonstrating disabling rate limiting for a specific log ---\")\nlogger.error(\"CRITICAL: Something went terribly wrong, do NOT rate-limit this!\", extra=RateLimit(stream_id=None))\nlogger.info(\"This info log will be rate-limited by default if repeated.\")\nlogger.info(\"This info log will be rate-limited by default if repeated.\")\n","lang":"python","description":"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)`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}