skillfed

django-structlog

Structured Logging for Django

django-structlog v10.1.0 3.7M downloads/30d#2,505 on PyPI528
Permissive license MIT Active released

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 on this page — 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

django-structlog on PyPI

pip

pip install django-structlog

uv

uv add django-structlog

poetry

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 the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 4 — django, structlog, asgiref, django-ipware
Maintenance actively maintained — 76 days since the last release
Last repo commit
First released
Downloads 3,749,882/month — #2,505 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: django_structlog-10.1.0-py3-none-any.whl

Development Status :: 5 - Production/StableFramework :: DjangoFramework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.1Framework :: Django :: 5.2License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: System :: LoggingTyping :: Typed

Tags

django structured loggingdjango request logging middlewarestructlog django integrationdjango json loggingdjango request tracking logsdjango context loggingdjango audit trail logging
request-tracingstructured-loggingdjango-middleware

More Logging packages