Registry / web-framework / django-guid

django-guid

JSON →
library3.6.1pypypi✓ verified 82d ago

django-guid is a Python middleware library for Django applications, enabling single request-response cycle tracing by injecting a unique ID (GUID) into project logs. It supports both ASGI and WSGI applications and includes integrations for tools like Sentry and Celery. The library is currently at version 3.5.2 and maintains an active release cadence, frequently updating to support new Django and Python versions.

pip install django-guid
INSTALL
IMPORT
SIG · DJANGO-GUID
D
django-guid
web-frameworkpythonv3.6.1
Install
3.6s avg
Import
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.6.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 67.2MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.6s · import 0.000s · 68MB
66MB installed
● package 66MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_guid
from django_guid import get_guid
from django_guid import GuidMiddleware
set_guid
from django_guid import set_guid
clear_guid
from django_guid import clear_guid

To quickly integrate `django-guid`, add `'django_guid'` to `INSTALLED_APPS` and `GuidMiddleware` to your `MIDDLEWARE` in `settings.py`. It's recommended to place the middleware at the top of the list. Crucially, configure your `LOGGING` dictionary to use the `django_guid.log_filters.CorrelationId` filter and include `{correlation_id}` in your formatter strings.

import logging from django.http import HttpResponse from django.conf import settings # Minimal settings.py content for quickstart settings.configure( INSTALLED_APPS=['django_guid'], MIDDLEWARE=['django_guid.middleware.GuidMiddleware'], LOGGING={ 'version': 1, 'disable_existing_loggers': False, 'filters': { 'correlation_id': { '()': 'django_guid.log_filters.CorrelationId' } }, 'formatters': { 'verbose': { 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {correlation_id} {message}', 'style': '{', }, }, 'handlers': { 'console': { 'class': 'logging.StreamHandler', 'formatter': 'verbose', 'filters': ['correlation_id'] }, }, 'loggers': { 'django': { 'handlers': ['console'], 'level': 'INFO', 'propagate': True, }, '': { # root logger 'handlers': ['console'], 'level': 'INFO', } } } ) logger = logging.getLogger(__name__) def my_view(request): logger.info("This log message will include the GUID.") return HttpResponse("Hello, world!") # To demonstrate outside a full Django runserver context (for testing): # from django.test import RequestFactory # from django_guid.middleware import GuidMiddleware # from django.urls import path # from django.core.handlers.wsgi import WSGIRequest # try: # from django.test.utils import setup_test_environment, teardown_test_environment # except ImportError: # # For Django < 1.10 # pass # if hasattr(settings, 'configure') and settings.configured is False: # settings.configure(DEBUG=True) # # Basic URLConf for demonstration # urlpatterns = [ # path('test-guid/', my_view), # ] # # Simulate a request (requires more setup for full Django context) # # This part is illustrative; a real test suite or `python manage.py runserver` is needed. # if __name__ == '__main__': # print("To run, integrate into a Django project with 'python manage.py runserver'.") # print("Ensure settings.py includes 'django_guid' in INSTALLED_APPS and GuidMiddleware.") # print("Logging configuration should apply 'correlation_id' filter as shown above.")
Debug
Known issues
breaking`django-guid` v3.4.0 introduced breaking changes by dropping support for Python 3.7 and Django versions lower than 3.2.
fix
Ensure your project is running on Python 3.8 or newer and Django 3.2 or newer before upgrading to `django-guid` v3.4.0 or later.
affects: >=3.4.0
gotchaThe GUID will not appear in your application logs if the `CorrelationId` filter is not correctly applied to your logging handlers and formatters in `settings.py`.
fix
Verify that your `LOGGING` configuration includes `django_guid.log_filters.CorrelationId` as a filter, that your handlers reference this filter, and that your formatters include the `{correlation_id}` placeholder.
affects: All
deprecatedDirect access to the GUID context variable moved from `django_guid.utils.guid_context` to `django_guid.context.guid_context` in `django-guid` v3.5.1.
fix
Update imports from `from django_guid.utils import guid_context` to `from django_guid.context import guid_context`.
affects: >=3.5.1
gotchaWhen using `django-guid` with Sentry, support for Sentry SDK v2 (`sentry>2`) was added in v3.5.2 for Celery integration. Ensure compatibility if you are using older Sentry SDK versions.
fix
If integrating with Sentry for Celery, consult the `django-guid` documentation for Sentry integration settings and ensure your Sentry SDK version is compatible or upgrade to Sentry SDK v2+.
affects: >=3.5.2
gotchaThe `UUID_FORMAT` setting (introduced in v3.3.0) defaults to `hex`. If you need the standard UUID string format with hyphens (e.g., `776336d4-545e-...`), you must explicitly configure it.
fix
Add `DJANGO_GUID = {'UUID_FORMAT': 'string'}` to your `settings.py` to enable the string format for generated UUIDs.
affects: >=3.3.0
Upgrade
Version history
3.6.1latest on PyPI · released May 5, 2026
Audit
Dependencies
DjangorequiredCore functionality is a Django middleware. Requires Django >= 3.2 for django-guid v3.4.0+.
sentry-sdkoptionalRequired for Sentry integration features (optional).
celeryoptionalRequired for Celery integration features (optional).
Agent activity
14 hits · last 30 days
node
14
Resources
django-guid — pip install django-guid · libregistry