{"id":2481,"library":"django-silk","title":"Django Silk","description":"Django Silk is a live profiling and inspection tool for the Django framework, designed to help developers identify performance bottlenecks. It intercepts and stores HTTP requests, responses, and database queries, presenting them in an intuitive user interface for detailed analysis. Currently at version 5.5.0, it maintains an active release cadence, supporting recent Django and Python versions.","status":"active","version":"5.5.0","language":"en","source_language":"en","source_url":"https://github.com/jazzband/django-silk","tags":["django","profiling","performance","debugging","web"],"install":[{"cmd":"pip install django-silk","lang":"bash","label":"Standard Installation"},{"cmd":"pip install django-silk[formatting]","lang":"bash","label":"With optional Python snippet formatting"}],"dependencies":[{"reason":"Core framework integration; tested with Django 4.2, 5.1, 5.2, 6.0.","package":"Django","optional":false}],"imports":[{"note":"Add 'silk' to your Django project's INSTALLED_APPS in settings.py.","symbol":"silk","correct":"INSTALLED_APPS = [... 'silk', ...]"},{"note":"Use MIDDLEWARE for modern Django versions (>= 1.10). Place SilkyMiddleware early in the list for comprehensive profiling.","wrong":"MIDDLEWARE_CLASSES = (... 'silk.middleware.SilkyMiddleware', ...)","symbol":"SilkyMiddleware","correct":"MIDDLEWARE = [... 'silk.middleware.SilkyMiddleware', ...]"},{"note":"Include 'silk.urls' in your project's main urls.py to access the Silk UI at '/silk/'.","symbol":"silk.urls","correct":"from django.urls import path, include\n\nurlpatterns = [\n    path('silk/', include('silk.urls', namespace='silk'))\n]"}],"quickstart":{"code":"# settings.py\nINSTALLED_APPS = [\n    # ... other apps\n    'silk',\n]\n\nMIDDLEWARE = [\n    # Place SilkyMiddleware near the top to capture full request cycle\n    # If using GZipMiddleware, place it *before* SilkyMiddleware.\n    # 'django.middleware.gzip.GZipMiddleware',\n    'silk.middleware.SilkyMiddleware',\n    # ... other middleware\n]\n\n# Optional: Restrict access to Silk UI\n# SILKY_AUTHENTICATION = True # Requires user to be logged in\n# SILKY_AUTHORISATION = True  # Requires logged-in user to be staff\n# LOGIN_URL = '/admin/login/' # Example for custom login URL if SILKY_AUTHENTICATION is True\n\n# urls.py\nfrom django.contrib import admin\nfrom django.urls import path, include\n\nurlpatterns = [\n    path('admin/', admin.site.urls),\n    path('silk/', include('silk.urls', namespace='silk')),\n    # ... other url patterns\n]\n\n# After configuration, run migrations:\n# python manage.py migrate\n# Access the UI at /silk/","lang":"python","description":"To quickly set up Django Silk, add 'silk' to `INSTALLED_APPS` and 'silk.middleware.SilkyMiddleware' to `MIDDLEWARE` in your Django settings. It's crucial to place `SilkyMiddleware` early in your `MIDDLEWARE` list to capture the entire request/response cycle; if using `GZipMiddleware`, place it before `SilkyMiddleware`. Finally, include 'silk.urls' in your project's `urls.py` and run `python manage.py migrate`."},"warnings":[{"fix":"Upgrade Python to 3.10+ and Django to 4.2+ or pin django-silk to a version prior to 5.3.0 (e.g., `django-silk==5.2.0`).","message":"Django Silk v5.3.0 removed support for Django 3.2 and Python 3.8. Ensure your environment meets the minimum requirements (Python >= 3.10, Django >= 4.2).","severity":"breaking","affected_versions":">=5.3.0"},{"fix":"Migrate your storage configuration from `SILKY_STORAGE_CLASS` to the `STORAGES` setting as per Django's official documentation.","message":"The `SILKY_STORAGE_CLASS` setting was deprecated in version 5.1.0. Users should now leverage Django's standard `STORAGES` configuration for specifying storage backends.","severity":"deprecated","affected_versions":">=5.1.0"},{"fix":"Place `silk.middleware.SilkyMiddleware` as high as possible in your `MIDDLEWARE` list. Ensure `django.middleware.gzip.GZipMiddleware` is positioned before it if used.","message":"The order of middleware is sensitive. If `silk.middleware.SilkyMiddleware` is placed after another middleware that returns a response without calling `get_response`, Silk will not profile that request. If using `django.middleware.gzip.GZipMiddleware`, it must be placed *before* `SilkyMiddleware` to avoid encoding errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Restrict Django Silk to development and staging environments. Use environment variables or Django settings to enable/disable it conditionally.","message":"Using Django Silk in production environments is generally not recommended due to performance overhead (intercepting and storing all request/response data), potential for significant database storage growth, and security implications (exposing application internals).","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure you are on the latest patch release (e.g., 5.4.3 or newer) and thoroughly test profiling with custom binary or JSON fields. Report any new issues to the maintainers.","message":"There have been recurring fixes related to serialization issues for binary and JSON fields, as well as race conditions when modifying SQL execution, in versions 5.4.x. While fixed, this indicates potential instability in complex serialization scenarios.","severity":"gotcha","affected_versions":"5.4.x"},{"fix":"Be aware of this limitation when profiling in multi-threaded or concurrent environments with Python 3.12+. Consider other profiling approaches for concurrent code sections if precise timing is needed across concurrent operations.","message":"When using Python 3.12 or later, the built-in `cProfile` (used by Silk for Python profiling) cannot run concurrently. This means if another profile is already running, Silk's Python profiler will not execute.","severity":"gotcha","affected_versions":">=3.12"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}