django-devbar 0.2.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.4
2
+ Name: django-devbar
3
+ Version: 0.4.0
4
+ Summary: Lightweight performance devbar for Django
5
+ Keywords: django,debug,performance,monitoring,development
6
+ Author: amureki
7
+ Author-email: amureki <oss@amureki.com>
8
+ License-Expression: MIT
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Framework :: Django
18
+ Classifier: Framework :: Django :: 4.2
19
+ Classifier: Framework :: Django :: 5.0
20
+ Classifier: Framework :: Django :: 5.1
21
+ Classifier: Framework :: Django :: 5.2
22
+ Classifier: Framework :: Django :: 6.0
23
+ Classifier: Topic :: Software Development
24
+ Classifier: Intended Audience :: Developers
25
+ Requires-Dist: django>=4.2
26
+ Requires-Python: >=3.10
27
+ Project-URL: Homepage, https://github.com/amureki/django-devbar
28
+ Project-URL: Issues, https://github.com/amureki/django-devbar/issues
29
+ Project-URL: Repository, https://github.com/amureki/django-devbar
30
+ Description-Content-Type: text/markdown
31
+
32
+ # django-devbar
33
+
34
+ Lightweight performance devbar for Django. Shows DB query count, query duration, application time, and detects duplicate queries with visual severity indicators.
35
+
36
+ Normal operation – showing query count, duration, and application time: ![devbar example](https://github.com/amureki/django-devbar/raw/3c6118d4283c211a5d84510de52e1d5c3e5e46e4/docs/devbar-example.svg)
37
+
38
+ Duplicate queries detected – severity indicator and details shown: ![devbar warning example](https://github.com/amureki/django-devbar/raw/3c6118d4283c211a5d84510de52e1d5c3e5e46e4/docs/devbar-example-warning.svg)
39
+
40
+ [![Chrome DevTools extension](https://github.com/user-attachments/assets/bc06af44-a0b3-4561-a13f-8007da53cb9e)](#chrome-extension)
41
+
42
+ > [!WARNING]
43
+ > This package is experimental and may introduce breaking changes in minor versions.
44
+
45
+ ## Motivation
46
+
47
+ While [Django Debug Toolbar](https://django-debug-toolbar.readthedocs.io/) is a proven tool trusted by countless projects, django-devbar explores a different approach to development debugging:
48
+
49
+ - **Minimal setup** — just add middleware, nothing else required
50
+ - **Browser DevTools integration** — Chrome extension panel works with any response type, including JSON
51
+ - **Zero extra dependencies** — only requires Django
52
+ - **Lower overhead** — no extra requests to debug endpoints
53
+ - **Non-intrusive** — HTML bar is optional; works via headers and DevTools panel alone
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ # Using uv (recommended)
59
+ uv add --dev django-devbar
60
+
61
+ # Or using pip
62
+ pip install django-devbar
63
+ ```
64
+
65
+ Add to your middleware as early as possible, but after any middleware that encodes the response (e.g., `GZipMiddleware`):
66
+
67
+ ```python
68
+ MIDDLEWARE = [
69
+ "django.middleware.security.SecurityMiddleware",
70
+ "django_devbar.DevBarMiddleware",
71
+ # ...
72
+ ]
73
+ ```
74
+
75
+ ## Configuration
76
+
77
+ All settings are optional. Configure via a `DEVBAR` dict in your Django settings:
78
+
79
+ ```python
80
+ DEVBAR = {
81
+ "POSITION": "bottom-right", # bottom-right (default), bottom-left, top-right, top-left
82
+ "SHOW_BAR": None, # follows DEBUG; set True/False to override
83
+ "ENABLE_DEVTOOLS_DATA": None, # follows DEBUG; set True/False to override
84
+ }
85
+ ```
86
+
87
+ ## Response Headers
88
+
89
+ Django DevBar adds HTTP response headers with performance metrics:
90
+
91
+ - **Server-Timing** (always present) – Standard HTTP header with database, application, and total time metrics. Visible in Chrome DevTools Network tab under Timing.
92
+
93
+ An additional header is included by default in DEBUG mode:
94
+
95
+ - **DevBar-Data** - JSON header with comprehensive metrics including duplicate query details
96
+
97
+ This is useful for:
98
+
99
+ - **API endpoints** where the HTML overlay can't be displayed
100
+ - **Automated testing** to assert performance metrics (e.g., fail CI if query count exceeds a limit)
101
+ - **Browser extensions** that need detailed duplicate query information
102
+
103
+ ### Server-Timing format
104
+
105
+ ```
106
+ Server-Timing: db;dur=87.50, app;dur=41.30, total;dur=128.80
107
+ ```
108
+
109
+ ## Chrome Extension
110
+
111
+ View Django DevBar metrics directly in Chrome DevTools with the [official extension](https://chromewebstore.google.com/detail/django-devbar/fehcaaopchkbknbdhjadnmehiifdmeid).
112
+
113
+ See [chrome-extension/README.md](chrome-extension/README.md) for more details.
@@ -0,0 +1,82 @@
1
+ # django-devbar
2
+
3
+ Lightweight performance devbar for Django. Shows DB query count, query duration, application time, and detects duplicate queries with visual severity indicators.
4
+
5
+ Normal operation – showing query count, duration, and application time: ![devbar example](https://github.com/amureki/django-devbar/raw/3c6118d4283c211a5d84510de52e1d5c3e5e46e4/docs/devbar-example.svg)
6
+
7
+ Duplicate queries detected – severity indicator and details shown: ![devbar warning example](https://github.com/amureki/django-devbar/raw/3c6118d4283c211a5d84510de52e1d5c3e5e46e4/docs/devbar-example-warning.svg)
8
+
9
+ [![Chrome DevTools extension](https://github.com/user-attachments/assets/bc06af44-a0b3-4561-a13f-8007da53cb9e)](#chrome-extension)
10
+
11
+ > [!WARNING]
12
+ > This package is experimental and may introduce breaking changes in minor versions.
13
+
14
+ ## Motivation
15
+
16
+ While [Django Debug Toolbar](https://django-debug-toolbar.readthedocs.io/) is a proven tool trusted by countless projects, django-devbar explores a different approach to development debugging:
17
+
18
+ - **Minimal setup** — just add middleware, nothing else required
19
+ - **Browser DevTools integration** — Chrome extension panel works with any response type, including JSON
20
+ - **Zero extra dependencies** — only requires Django
21
+ - **Lower overhead** — no extra requests to debug endpoints
22
+ - **Non-intrusive** — HTML bar is optional; works via headers and DevTools panel alone
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ # Using uv (recommended)
28
+ uv add --dev django-devbar
29
+
30
+ # Or using pip
31
+ pip install django-devbar
32
+ ```
33
+
34
+ Add to your middleware as early as possible, but after any middleware that encodes the response (e.g., `GZipMiddleware`):
35
+
36
+ ```python
37
+ MIDDLEWARE = [
38
+ "django.middleware.security.SecurityMiddleware",
39
+ "django_devbar.DevBarMiddleware",
40
+ # ...
41
+ ]
42
+ ```
43
+
44
+ ## Configuration
45
+
46
+ All settings are optional. Configure via a `DEVBAR` dict in your Django settings:
47
+
48
+ ```python
49
+ DEVBAR = {
50
+ "POSITION": "bottom-right", # bottom-right (default), bottom-left, top-right, top-left
51
+ "SHOW_BAR": None, # follows DEBUG; set True/False to override
52
+ "ENABLE_DEVTOOLS_DATA": None, # follows DEBUG; set True/False to override
53
+ }
54
+ ```
55
+
56
+ ## Response Headers
57
+
58
+ Django DevBar adds HTTP response headers with performance metrics:
59
+
60
+ - **Server-Timing** (always present) – Standard HTTP header with database, application, and total time metrics. Visible in Chrome DevTools Network tab under Timing.
61
+
62
+ An additional header is included by default in DEBUG mode:
63
+
64
+ - **DevBar-Data** - JSON header with comprehensive metrics including duplicate query details
65
+
66
+ This is useful for:
67
+
68
+ - **API endpoints** where the HTML overlay can't be displayed
69
+ - **Automated testing** to assert performance metrics (e.g., fail CI if query count exceeds a limit)
70
+ - **Browser extensions** that need detailed duplicate query information
71
+
72
+ ### Server-Timing format
73
+
74
+ ```
75
+ Server-Timing: db;dur=87.50, app;dur=41.30, total;dur=128.80
76
+ ```
77
+
78
+ ## Chrome Extension
79
+
80
+ View Django DevBar metrics directly in Chrome DevTools with the [official extension](https://chromewebstore.google.com/detail/django-devbar/fehcaaopchkbknbdhjadnmehiifdmeid).
81
+
82
+ See [chrome-extension/README.md](chrome-extension/README.md) for more details.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "django-devbar"
3
- version = "0.2.0"
3
+ version = "0.4.0"
4
4
  description = "Lightweight performance devbar for Django"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -12,7 +12,7 @@ def get_config():
12
12
  return {
13
13
  "POSITION": "bottom-right",
14
14
  "SHOW_BAR": None, # None = use settings.DEBUG
15
- "SHOW_HEADERS": False,
15
+ "ENABLE_DEVTOOLS_DATA": None, # None = use settings.DEBUG
16
16
  **getattr(settings, "DEVBAR", {}),
17
17
  }
18
18
 
@@ -29,5 +29,7 @@ def get_show_bar():
29
29
  return settings.DEBUG if show_bar is None else show_bar
30
30
 
31
31
 
32
- def get_show_headers():
33
- return get_config()["SHOW_HEADERS"]
32
+ def get_enable_devtools_data():
33
+ config = get_config()
34
+ enable = config["ENABLE_DEVTOOLS_DATA"]
35
+ return settings.DEBUG if enable is None else enable
@@ -1,3 +1,4 @@
1
+ import json
1
2
  import re
2
3
  from contextlib import ExitStack
3
4
  from pathlib import Path
@@ -8,9 +9,9 @@ from django.template import Context, Engine
8
9
 
9
10
  from . import tracker
10
11
  from .conf import (
12
+ get_enable_devtools_data,
11
13
  get_position,
12
14
  get_show_bar,
13
- get_show_headers,
14
15
  )
15
16
 
16
17
  BODY_CLOSE_RE = re.compile(rb"</body\s*>", re.IGNORECASE)
@@ -45,22 +46,35 @@ class DevBarMiddleware:
45
46
  stats["python_time"] = python_time
46
47
  stats["total_time"] = total_time
47
48
 
48
- level = "warn" if stats["has_duplicates"] else "ok"
49
+ if get_enable_devtools_data():
50
+ self._add_devtools_data_header(response, stats)
49
51
 
50
- if get_show_headers():
51
- self._add_headers(response, stats)
52
+ self._add_server_timing_header(response, stats)
52
53
 
53
54
  if get_show_bar() and self._can_inject(response):
54
- self._inject_devbar(response, stats, level)
55
+ self._inject_devbar(response, stats)
55
56
 
56
57
  return response
57
58
 
58
- def _add_headers(self, response, stats):
59
- response["DevBar-Query-Count"] = str(stats["count"])
60
- response["DevBar-DB-Time"] = f"{stats['duration']:.0f}ms"
61
- response["DevBar-App-Time"] = f"{stats['python_time']:.0f}ms"
62
- if stats["has_duplicates"]:
63
- response["DevBar-Duplicates"] = str(len(stats["duplicate_queries"]))
59
+ def _add_devtools_data_header(self, response, stats):
60
+ extension_data = {
61
+ "count": stats["count"],
62
+ "db_time": stats["duration"],
63
+ "app_time": stats["python_time"],
64
+ "total_time": stats["total_time"],
65
+ }
66
+ if stats.get("duplicate_queries"):
67
+ extension_data["duplicates"] = stats["duplicate_queries"]
68
+
69
+ response["DevBar-Data"] = json.dumps(extension_data)
70
+
71
+ def _add_server_timing_header(self, response, stats):
72
+ parts = [
73
+ f"db;dur={stats['duration']:.2f}",
74
+ f"app;dur={stats['python_time']:.2f}",
75
+ f"total;dur={stats['total_time']:.2f}",
76
+ ]
77
+ response["Server-Timing"] = ", ".join(parts)
64
78
 
65
79
  def _can_inject(self, response):
66
80
  if getattr(response, "streaming", False):
@@ -72,7 +86,7 @@ class DevBarMiddleware:
72
86
  return False
73
87
  return hasattr(response, "content")
74
88
 
75
- def _inject_devbar(self, response, stats, level):
89
+ def _inject_devbar(self, response, stats):
76
90
  content = response.content
77
91
  matches = list(BODY_CLOSE_RE.finditer(content))
78
92
  if not matches:
@@ -87,7 +101,6 @@ class DevBarMiddleware:
87
101
  Context(
88
102
  {
89
103
  "position": get_position(),
90
- "level": level,
91
104
  "db_time": stats["duration"],
92
105
  "app_time": stats["python_time"],
93
106
  "query_count": stats["count"],
@@ -14,6 +14,7 @@
14
14
  color: #f5f5f5;
15
15
  }
16
16
  #django-devbar.level-warn { border-left: 3px solid #f59e0b; }
17
+ #django-devbar.has-duplicates { border-left: 3px solid #f59e0b; }
17
18
  #django-devbar span { opacity: 0.7; }
18
19
  #django-devbar strong { opacity: 1; font-weight: 600; }
19
20
  #django-devbar details { display: inline; position: relative; }
@@ -85,8 +86,8 @@
85
86
  }
86
87
  @media (max-width: 640px) { #django-devbar { display: none; } }
87
88
  </style>
88
- <div id="django-devbar" class="level-{{ level }}">
89
+ <div id="django-devbar"{% if duplicates_html %} class="has-duplicates"{% endif %}>
90
+ <span>queries</span> <strong>{{ query_count }}</strong> <span>·</span>
89
91
  <span>db</span> <strong>{{ db_time|floatformat:0 }}ms</strong> <span>·</span>
90
- <span>app</span> <strong>{{ app_time|floatformat:0 }}ms</strong> <span>·</span>
91
- <span>queries</span> <strong>{{ query_count }}</strong>{{ duplicates_html|safe }}
92
+ <span>app</span> <strong>{{ app_time|floatformat:0 }}ms</strong>{{ duplicates_html|safe }}
92
93
  </div>
@@ -18,7 +18,6 @@ def get_stats():
18
18
  return {
19
19
  "count": _query_count.get(),
20
20
  "duration": _query_duration.get(),
21
- "has_duplicates": bool(_duplicate_log.get()),
22
21
  "duplicate_queries": _duplicate_log.get(),
23
22
  }
24
23
 
@@ -1,89 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: django-devbar
3
- Version: 0.2.0
4
- Summary: Lightweight performance devbar for Django
5
- Keywords: django,debug,performance,monitoring,development
6
- Author: amureki
7
- Author-email: amureki <oss@amureki.com>
8
- License-Expression: MIT
9
- Classifier: Programming Language :: Python
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3 :: Only
12
- Classifier: Programming Language :: Python :: 3.10
13
- Classifier: Programming Language :: Python :: 3.11
14
- Classifier: Programming Language :: Python :: 3.12
15
- Classifier: Programming Language :: Python :: 3.13
16
- Classifier: Programming Language :: Python :: 3.14
17
- Classifier: Framework :: Django
18
- Classifier: Framework :: Django :: 4.2
19
- Classifier: Framework :: Django :: 5.0
20
- Classifier: Framework :: Django :: 5.1
21
- Classifier: Framework :: Django :: 5.2
22
- Classifier: Framework :: Django :: 6.0
23
- Classifier: Topic :: Software Development
24
- Classifier: Intended Audience :: Developers
25
- Requires-Dist: django>=4.2
26
- Requires-Python: >=3.10
27
- Project-URL: Homepage, https://github.com/amureki/django-devbar
28
- Project-URL: Issues, https://github.com/amureki/django-devbar/issues
29
- Project-URL: Repository, https://github.com/amureki/django-devbar
30
- Description-Content-Type: text/markdown
31
-
32
- # django-devbar
33
-
34
- Lightweight performance devbar for Django. Shows DB query count, query duration, application time, and detects duplicate queries with visual severity indicators.
35
-
36
- ![devbar example](https://github.com/amureki/django-devbar/raw/3c6118d4283c211a5d84510de52e1d5c3e5e46e4/docs/devbar-example.svg)
37
-
38
- ![devbar warning example](https://github.com/amureki/django-devbar/raw/3c6118d4283c211a5d84510de52e1d5c3e5e46e4/docs/devbar-example-warning.svg)
39
-
40
- > **Note:** This package is experimental and may introduce breaking changes in minor versions.
41
-
42
- ## Installation
43
-
44
- ```bash
45
- # Using uv (recommended)
46
- uv add --dev django-devbar
47
-
48
- # Or using pip
49
- pip install django-devbar
50
- ```
51
-
52
- Add to your middleware as early as possible, but after any middleware that encodes the response (e.g., `GZipMiddleware`):
53
-
54
- ```python
55
- MIDDLEWARE = [
56
- "django.middleware.security.SecurityMiddleware",
57
- "django_devbar.DevBarMiddleware",
58
- # ...
59
- ]
60
- ```
61
-
62
- ## Configuration
63
-
64
- All settings are optional. Configure via a `DEVBAR` dict in your Django settings:
65
-
66
- ```python
67
- DEVBAR = {
68
- 'POSITION': 'bottom-right', # bottom-right, bottom-left, top-right, top-left
69
- 'SHOW_BAR': None, # None (default) = follows DEBUG, or True/False to override
70
- 'SHOW_HEADERS': False, # Add X-DevBar-* headers to responses
71
- }
72
- ```
73
-
74
- ## Response Headers
75
-
76
- When `DEVBAR = {'SHOW_HEADERS': True}`, performance metrics are added as HTTP response headers. This is useful for:
77
-
78
- - **API endpoints** where the HTML overlay can't be displayed
79
- - **Automated testing** to assert performance metrics (e.g., fail CI if query count exceeds a limit)
80
- - **Monitoring tools** that can capture and aggregate header values
81
-
82
- Headers included:
83
-
84
- | Header | Example | Description |
85
- |--------|---------|-------------|
86
- | `DevBar-Query-Count` | `12` | Number of database queries executed |
87
- | `DevBar-DB-Time` | `87ms` | Total time spent in database queries |
88
- | `DevBar-App-Time` | `41ms` | Application time (total time minus DB time) |
89
- | `DevBar-Duplicates` | `3` | Number of duplicate queries detected (only present if duplicates found) |
@@ -1,58 +0,0 @@
1
- # django-devbar
2
-
3
- Lightweight performance devbar for Django. Shows DB query count, query duration, application time, and detects duplicate queries with visual severity indicators.
4
-
5
- ![devbar example](https://github.com/amureki/django-devbar/raw/3c6118d4283c211a5d84510de52e1d5c3e5e46e4/docs/devbar-example.svg)
6
-
7
- ![devbar warning example](https://github.com/amureki/django-devbar/raw/3c6118d4283c211a5d84510de52e1d5c3e5e46e4/docs/devbar-example-warning.svg)
8
-
9
- > **Note:** This package is experimental and may introduce breaking changes in minor versions.
10
-
11
- ## Installation
12
-
13
- ```bash
14
- # Using uv (recommended)
15
- uv add --dev django-devbar
16
-
17
- # Or using pip
18
- pip install django-devbar
19
- ```
20
-
21
- Add to your middleware as early as possible, but after any middleware that encodes the response (e.g., `GZipMiddleware`):
22
-
23
- ```python
24
- MIDDLEWARE = [
25
- "django.middleware.security.SecurityMiddleware",
26
- "django_devbar.DevBarMiddleware",
27
- # ...
28
- ]
29
- ```
30
-
31
- ## Configuration
32
-
33
- All settings are optional. Configure via a `DEVBAR` dict in your Django settings:
34
-
35
- ```python
36
- DEVBAR = {
37
- 'POSITION': 'bottom-right', # bottom-right, bottom-left, top-right, top-left
38
- 'SHOW_BAR': None, # None (default) = follows DEBUG, or True/False to override
39
- 'SHOW_HEADERS': False, # Add X-DevBar-* headers to responses
40
- }
41
- ```
42
-
43
- ## Response Headers
44
-
45
- When `DEVBAR = {'SHOW_HEADERS': True}`, performance metrics are added as HTTP response headers. This is useful for:
46
-
47
- - **API endpoints** where the HTML overlay can't be displayed
48
- - **Automated testing** to assert performance metrics (e.g., fail CI if query count exceeds a limit)
49
- - **Monitoring tools** that can capture and aggregate header values
50
-
51
- Headers included:
52
-
53
- | Header | Example | Description |
54
- |--------|---------|-------------|
55
- | `DevBar-Query-Count` | `12` | Number of database queries executed |
56
- | `DevBar-DB-Time` | `87ms` | Total time spent in database queries |
57
- | `DevBar-App-Time` | `41ms` | Application time (total time minus DB time) |
58
- | `DevBar-Duplicates` | `3` | Number of duplicate queries detected (only present if duplicates found) |