A structured logging library for Python that emits machine-parseable log events (JSON, key-value) instead of free-text — the foundation for log aggregation, search, and alerting.
structlog wraps Python's standard logging with a structured-event model: every log call passes key-value context (user_id, request_id, latency_ms) that gets serialized into JSON or key-value text. Downstream log aggregators (Datadog, Splunk, Loki) can search and filter on those fields. Compared to f-string logging, structured logs make incident triage dramatically faster — you can ask 'show me all 500 errors for user X in the last hour' as a query.
Replacing logger.info(f'User {user_id} failed payment {payment_id}: {error}') with logger.info('payment.failed', user_id=user_id, payment_id=payment_id, error=str(error)) for queryable logs.
Structured logging is the difference between 'grep through 50GB of text' and 'filter for user_id=X status=500' — order-of-magnitude faster incident response.
Need help implementing this in your business?
Get Started