mdc
Mapped Diagnostic Context (MDC) library for python
What it is and what it does
MDC is a logging enhancement library that integrates with Python's standard logging module to attach diagnostic context to log messages. It provides a context manager and decorator to inject key-value pairs into logs, which are then formatted as structured JSON output by the MDCHandler. The library automatically captures standard logging fields (message, logger name, timestamp, level) and adds MDC-specific context alongside them, making it useful for tracing requests or operations through distributed systems or complex applications.
The package has no runtime dependencies and is designed as a drop-in handler for the logging module. However, it is abandoned—last released in September 2019 with no active maintenance. The repository is archived, and the license terms are undocumented, creating uncertainty about legal use and future compatibility with newer Python versions.
Use it for:
- Attach request IDs or user context to all log entries within a request handler using the MDC context manager.
- Decorate functions with @with_mdc to automatically inject operation-specific fields into logs for that function's execution.
- Emit structured JSON logs that include both standard logging metadata and custom diagnostic fields for log aggregation systems.
- Trace execution flow across async or threaded code by maintaining context-local diagnostic information.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds Mapped Diagnostic Context (MDC) support to Python's standard logging library, allowing you to attach contextual fields to log messages via context managers and decorators.
No. The package is abandoned (last release September 2019, repository archived), license terms are undocumented, and it has high install friction. While it has no known vulnerabilities and no runtime dependencies, the lack of maintenance and unclear licensing make it unsuitable for new projects. Consider modern alternatives with active maintenance for structured logging with context support.
Install
mdc on PyPI
pip
pip install mdcuv
uv add mdcpoetry
poetry add mdcInstalling mdc
Before you install
High install friction due to source-only distribution. The package is abandoned as of 2019-09-09 with no recent maintenance; the repository is archived and the last commit was 2024-02-08 with no active development.
License in practice
License status is unclear—no SPDX identifier or raw license text is available in the package metadata, making it difficult to assess legal compatibility before use.
Quickstart
pip install mdc
import logging
from mdc import MDCHandler, MDC
logging.basicConfig(level=logging.DEBUG, handlers=[MDCHandler()])
with MDC(foo='bar'):
logging.warning('test message')
No explicit Python version requirement specified; package declares support for both Python 2 and Python 3 but Python 2 is end-of-life.
Verify before relying
- Whether the package works reliably with modern Python 3 versions given its age and lack of maintenance.
- Actual license terms, since license metadata is missing from the package.
- Whether the JSON output format changes mentioned in version 1.2.0 are stable or if further breaking changes are expected.
Package facts
| License | not declared (unclear) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | abandoned — 2,531 days since the last release |
| Last repo commit | (repository archived) |
| First released | |
| Downloads | 118,883/month — #12,102 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: mdc-1.2.1.tar.gz
Keywords: logging, mdc, context
Tags
More Logging packages
Wraps any iterable to display a real-time…
copyleft · top 100 on PyPI
python-json-loggerFormats Python logging output as JSON, making…
permissive · top 1,000 on PyPI
structlogstructlog is a structured logging library that…
permissive · top 1,000 on PyPI
loguruLoguru provides a pre-configured logger that…
permissive · top 1,000 on PyPI
coloredlogsAdds colored output to Python's standard…
permissive · top 1,000 on PyPI
wandbwandb is a machine learning experiment tracking…
permissive · top 1,000 on PyPI
datadog-loggerSends Python log messages to Datadog as Events…
permissive · top 15,000 on PyPI
daiquiriDaiquiri simplifies Python logging…
permissive · top 15,000 on PyPI
logfmterFormats Python stdlib logging output as logfmt…
permissive · top 15,000 on PyPI
google-cloud-loggingWrites log entries to Google Cloud Logging and…
permissive · top 1,000 on PyPI
google-cloud-appengine-loggingClient library for Google Cloud AppEngine…
permissive · top 1,000 on PyPI
django-structlogIntegrates structured logging into Django…
permissive · top 5,000 on PyPI
mo-logsProvides structured JSON logging with…
copyleft · top 15,000 on PyPI
icd-mappingsMaps ICD diagnostic codes between versions…
permissive · top 15,000 on PyPI
logstash_formatterFormats Python logging output as JSON objects…
permissive · top 15,000 on PyPI
google-cloud-bigquery-loggingPython client library for Google Cloud BigQuery…
permissive · top 15,000 on PyPI