API Reference¶
Complete API documentation for debug-toolbar.
Core¶
Configuration¶
- class debug_toolbar.core.config.DebugToolbarConfig¶
Base configuration for the debug toolbar.
Panel Base Class¶
- class debug_toolbar.core.panel.Panel¶
Base class for debug toolbar panels.
- Variables:
panel_id – Unique identifier for the panel
title – Display title
template – Template name for rendering
has_content – Whether panel has expandable content
- async generate_stats(context: RequestContext) dict[str, Any]¶
Generate statistics for this panel.
- generate_server_timing(context: RequestContext) str¶
Generate Server-Timing header value.
Request Context¶
- class debug_toolbar.core.context.RequestContext¶
Request-scoped context using contextvars.
- Parameters:
request_id (UUID) – Unique request identifier
start_time (float) – Request start timestamp
- classmethod get_current() RequestContext | None¶
Get the current request context.
- classmethod set_current(context: RequestContext) None¶
Set the current request context.
Storage¶
Litestar Integration¶
Plugin¶
- class debug_toolbar.litestar.plugin.DebugToolbarPlugin¶
Litestar plugin for the debug toolbar.
- Parameters:
config (LitestarDebugToolbarConfig) – Toolbar configuration
Example:
from litestar import Litestar from debug_toolbar.litestar import DebugToolbarPlugin, LitestarDebugToolbarConfig config = LitestarDebugToolbarConfig(enabled=True) app = Litestar(plugins=[DebugToolbarPlugin(config)])
Configuration¶
- class debug_toolbar.litestar.config.LitestarDebugToolbarConfig¶
Litestar-specific configuration extending DebugToolbarConfig.
Middleware¶
- class debug_toolbar.litestar.middleware.DebugToolbarMiddleware¶
ASGI middleware that injects the toolbar into HTML responses.
Built-in Panels¶
Timer Panel¶
- class debug_toolbar.core.panels.timer.TimerPanel¶
Displays request timing information.
Stats:
total_time: Total request duration (ms)user_cpu_time: User CPU timesystem_cpu_time: System CPU time
Request Panel¶
- class debug_toolbar.core.panels.request.RequestPanel¶
Displays HTTP request information.
Stats:
method: HTTP methodpath: Request pathquery_params: Query string parametersheaders: Request headerscookies: Request cookies
Response Panel¶
- class debug_toolbar.core.panels.response.ResponsePanel¶
Displays HTTP response information.
Stats:
status_code: Response statusheaders: Response headerscontent_length: Response size
Headers Panel¶
- class debug_toolbar.core.panels.headers.HeadersPanel¶
Categorized display of HTTP headers with security analysis.
Categories:
Security headers (CSP, HSTS, X-Frame-Options)
Caching headers
CORS headers
Authentication headers (redacted)
Logging Panel¶
- class debug_toolbar.core.panels.logging.LoggingPanel¶
Captures log records during request processing.
Stats:
records: List of log records with level, message, timestamp
Profiling Panel¶
- class debug_toolbar.core.panels.profiling.ProfilingPanel¶
CPU profiling with cProfile or pyinstrument.
- Variables:
profiler_backend – “cprofile” or “pyinstrument”
Alerts Panel¶
- class debug_toolbar.core.panels.alerts.AlertsPanel¶
Proactive issue detection panel.
Detection Categories:
Security: Missing headers, insecure cookies, CSRF issues
Performance: Large responses, slow queries
Database: N+1 patterns, query optimization
Configuration: Debug mode in production
Stats:
alerts: List of detected alerts with severity and suggestionstotal_alerts: Total alert countby_severity: Counts by severity levelby_category: Counts by category
Memory Panel¶
- class debug_toolbar.core.panels.memory.MemoryPanel¶
Memory profiling with multiple backend support.
Backends:
tracemalloc: Built-in Python tracer (default)memray: Advanced profiler (Linux/macOS, requires install)
Stats:
memory_before: Memory at request startmemory_after: Memory at request endmemory_delta: Memory change during requesttop_allocations: Largest allocations by file/line
SQLAlchemy Panel¶
- class debug_toolbar.extras.advanced_alchemy.panel.SQLAlchemyPanel¶
Tracks SQLAlchemy queries with timing and EXPLAIN support.
Stats:
queries: List of executed queriestotal_queries: Query counttotal_time: Total query timeduplicate_queries: Detected duplicate queriesn_plus_one_groups: Detected N+1 query patterns
Features:
Query timing
Parameter display
Duplicate detection
N+1 query detection with fix suggestions
EXPLAIN query plans (PostgreSQL, SQLite, MySQL, MariaDB)
Litestar-Specific Panels¶
Routes Panel¶
- class debug_toolbar.litestar.panels.routes.RoutesPanel¶
Displays all registered routes in the Litestar application.
Stats:
routes: List of all routes with methods and handlerscurrent_route: The matched route for this request
Events Panel¶
- class debug_toolbar.litestar.panels.events.EventsPanel¶
Tracks Litestar lifecycle events and hooks.
Stats:
lifecycle_hooks: on_startup, on_shutdown handlersrequest_hooks: before_request, after_request, after_response handlersexception_handlers: Registered exception handlersexecuted_hooks: Hooks that ran during this request
Module Reference¶
Configuration system for the debug toolbar. |
|
Base panel class for debug toolbar panels. |
|
Request context management using contextvars for async-safe data propagation. |
|
Storage backend for toolbar request history using LRU cache. |
|
Main debug toolbar manager class. |
|
Built-in panels for the async debug toolbar. |
|
Debug toolbar plugin for Litestar. |
|
Litestar-specific configuration for the debug toolbar. |
|
Debug toolbar middleware for Litestar. |
|
Litestar-specific panels for the debug toolbar. |