--- id: django-structlog version: "10.1.0" license: MIT license_treatment: permissive maintenance: active --- # django-structlog — Structured Logging for Django License: permissive · Maintenance: active · Downloads: 3.7M/mo ## What it is and what it does django-structlog is a middleware and signal-based integration layer that adds structured logging to Django applications. It automatically captures request context—request ID, user ID, IP address—and binds it to every log entry within that request's lifecycle, making logs queryable and traceable. Instead of flat text logs, you get rich metadata in JSON or key-value formats that can be searched, aggregated, and correlated across your application. The package works by installing a middleware component that generates a unique request ID and extracts user information from the request, then uses structlog's context-variable binding to attach this metadata to all logs emitted during request processing. It supports Django REST Framework and django-ninja out of the box, and provides signal hooks to bind additional custom metadata. Logs can be rendered as JSON for log aggregation systems, flat key-value lines for grep-friendly searching, or console output for development. Use it for: - Track requests end-to-end by searching logs with a request ID across multiple services or log files. - Correlate user actions with errors and performance issues by having user_id automatically included in every log. - Aggregate and analyze logs in JSON format using tools like jq or centralized logging platforms (ELK, Datadog, etc.). - Debug multi-user applications by filtering logs by IP address or user ID without manual context passing. - Extend logging metadata with custom request attributes (domain, tenant ID, feature flags) via signal receivers. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Integrates structured logging into Django applications using structlog, automatically capturing request metadata like request IDs, user IDs, and IP addresses in each log entry. Yes. django-structlog is actively maintained, has no known vulnerabilities, uses a permissive MIT license, and low install friction. It solves a real problem—correlating logs across requests—that becomes critical as Django applications grow beyond single-server deployments. If you need queryable, structured logs with automatic request context binding, this is a straightforward addition to your Django stack. ## Install pip install django-structlog uv add django-structlog poetry add django-structlog ## Installing django-structlog Before you install: Low install friction with a pure Python wheel distribution. The package is actively maintained with a recent release, and depends only on django, structlog, asgiref, and django-ipware—all standard, well-established libraries. License in practice: MIT license is permissive; you can use, modify, and distribute this package freely in commercial and open-source projects with minimal restrictions. Quickstart: pip install django-structlog # In settings.py INSTALLED_APPS: INSTALLED_APPS = ["django_structlog"] # In settings.py MIDDLEWARE: MIDDLEWARE = ["django_structlog.middlewares.RequestMiddleware"] # Then log with structlog: import structlog logger = structlog.get_logger(__name__) logger.info("event_name", key="value") Requires Python 3.10 or later; structlog configuration in Django settings.py is necessary for output formatting (JSON, key-value, or console). Verify before relying: - Whether Celery task logging integration requires significant additional setup beyond what the documentation covers. - Performance impact of automatic request metadata binding on high-throughput Django applications. - Compatibility with async Django views and ASGI servers beyond the asgiref dependency. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 3.7M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags django structured logging, django request logging middleware, structlog django integration, django json logging, django request tracking logs, django context logging, django audit trail logging, request-tracing, structured-logging, django-middleware [View on SkillFed](https://skillfed.io/packages/django-structlog) · [View on PyPI](https://pypi.org/project/django-structlog/)