debug_toolbar.core.panels¶
Built-in panels for the async debug toolbar.
- class debug_toolbar.core.panels.AlertsPanel(toolbar)[source]¶
Panel displaying proactive alerts for potential issues.
Detects and warns about: - Security issues (CSRF, insecure cookies, missing headers) - Performance problems (slow queries, large responses) - Database issues (N+1 queries) - Configuration problems (debug mode in production)
Get the navigation subtitle showing alert count and severity.
- Return type:
- class debug_toolbar.core.panels.AsyncProfilerPanel(toolbar)[source]¶
Panel for profiling async task execution and event loop behavior.
Tracks: - Async task creation and completion via task factory hooks - Blocking calls that stall the event loop - Event loop lag monitoring - Timeline visualization of concurrent execution
- Configure via toolbar config:
async_profiler_backend: “taskfactory” | “yappi” | “auto” (default: “auto”) async_blocking_threshold_ms: float (default: 100.0) async_enable_blocking_detection: bool (default: True) async_enable_event_loop_monitoring: bool (default: True) async_capture_task_stacks: bool (default: True) async_max_stack_depth: int (default: 10)
- __init__(toolbar)[source]¶
Initialize the async profiler panel.
- Parameters:
toolbar (
DebugToolbar) – The parent DebugToolbar instance.
- generate_server_timing(context)[source]¶
Generate Server-Timing header data for async profiling overhead.
- Parameters:
context (
RequestContext) – The current request context.- Return type:
- Returns:
Dictionary mapping metric names to durations in seconds.
- async generate_stats(context)[source]¶
Generate async profiling statistics.
- Parameters:
context (
RequestContext) – The current request context.- Return type:
- Returns:
Dictionary of async profiling statistics.
Get the navigation subtitle showing task count or warnings.
- Return type:
- Returns:
Formatted subtitle string.
- async process_request(context)[source]¶
Start async profiling at request start.
- Parameters:
context (
RequestContext) – The current request context.- Return type:
- async process_response(context)[source]¶
Stop async profiling at response completion.
- Parameters:
context (
RequestContext) – The current request context.- Return type:
- class debug_toolbar.core.panels.CachePanel(toolbar)[source]¶
Panel displaying cache operations during the request.
Tracks: - Cache operations (GET, SET, DELETE, etc.) - Hit/miss status - Operation duration - Backend type (Redis, memcached) - Aggregate statistics
- __init__(toolbar)[source]¶
Initialize the panel.
- Parameters:
toolbar (
DebugToolbar) – The parent DebugToolbar instance.
Get the navigation subtitle showing cache stats.
- Return type:
- class debug_toolbar.core.panels.HeadersPanel(toolbar)[source]¶
Panel displaying detailed HTTP header analysis.
Analyzes both request and response headers, providing: - Categorization by type (authentication, content, caching, CORS, security, custom) - Authorization header parsing and analysis - Cookie inspection and counting - Cache-Control directive parsing - Security header detection and validation - CORS header analysis
- AUTHENTICATION_HEADERS = frozenset({'authorization', 'proxy-authenticate', 'proxy-authorization', 'www-authenticate'})¶
- CACHING_HEADERS = frozenset({'age', 'cache-control', 'etag', 'expires', 'if-match', 'if-modified-since', 'if-none-match', 'if-unmodified-since', 'last-modified', 'pragma', 'vary'})¶
- CONTENT_HEADERS = frozenset({'accept', 'accept-charset', 'accept-encoding', 'accept-language', 'content-disposition', 'content-encoding', 'content-language', 'content-length', 'content-location', 'content-md5', 'content-range', 'content-type'})¶
- CORS_HEADERS = frozenset({'access-control-allow-credentials', 'access-control-allow-headers', 'access-control-allow-methods', 'access-control-allow-origin', 'access-control-expose-headers', 'access-control-max-age', 'access-control-request-headers', 'access-control-request-method', 'origin'})¶
- RECOMMENDED_SECURITY_HEADERS = frozenset({'content-security-policy', 'strict-transport-security', 'x-content-type-options', 'x-frame-options'})¶
- SECURITY_HEADERS = frozenset({'content-security-policy', 'content-security-policy-report-only', 'cross-origin-embedder-policy', 'cross-origin-opener-policy', 'cross-origin-resource-policy', 'permissions-policy', 'referrer-policy', 'strict-transport-security', 'x-content-type-options', 'x-frame-options', 'x-xss-protection'})¶
Get the navigation subtitle.
- Return type:
- class debug_toolbar.core.panels.LoggingPanel(toolbar)[source]¶
Panel displaying log records captured during the request.
Shows: - Log level - Logger name - Message - Source location - Exception info (if present)
- __init__(toolbar)[source]¶
Initialize the panel.
- Parameters:
toolbar (
DebugToolbar) – The parent DebugToolbar instance.
Get the navigation subtitle showing log count.
- Return type:
- class debug_toolbar.core.panels.MemoryPanel(toolbar)[source]¶
Panel for profiling memory allocations during request processing.
Supports multiple profiling backends: - tracemalloc: Standard library profiler (default, always available) - memray: Bloomberg’s profiler with C extension tracking (Linux/macOS only)
The panel automatically selects the best available backend based on platform and installed dependencies, with an option to override via config.
- Features:
Before/after memory snapshots
Memory delta tracking
Peak memory monitoring
Top allocations by file and line
Multi-backend support with automatic selection
- Configure via toolbar config:
memory_backend: “tracemalloc” | “memray” | “auto” (default: “auto”)
- __init__(toolbar)[source]¶
Initialize the memory panel with appropriate backend.
- Parameters:
toolbar (
DebugToolbar) – The parent DebugToolbar instance.
- generate_server_timing(context)[source]¶
Generate Server-Timing header data for memory profiling overhead.
- Parameters:
context (
RequestContext) – The current request context.- Return type:
- Returns:
Dictionary mapping metric names to durations in seconds.
- async generate_stats(context)[source]¶
Generate memory profiling statistics.
- Parameters:
context (
RequestContext) – The current request context.- Return type:
- Returns:
Dictionary of memory statistics.
Get the navigation subtitle showing memory delta.
- Return type:
- Returns:
Formatted memory delta string (e.g., “+2.3 MB” or “-500 KB”).
- async process_request(context)[source]¶
Start memory profiling at request start.
- Parameters:
context (
RequestContext) – The current request context.- Return type:
- async process_response(context)[source]¶
Stop memory profiling at response completion.
- Parameters:
context (
RequestContext) – The current request context.- Return type:
- class debug_toolbar.core.panels.ProfilingPanel(toolbar)[source]¶
Panel for profiling request performance.
Supports two profiling backends: - cProfile: Standard library profiler (default) - pyinstrument: Optional third-party profiler (more readable output)
The profiler tracks function calls, execution time, and generates detailed statistics about performance hotspots.
- Configure via toolbar config:
profiler_backend: “cprofile” | “pyinstrument” (default: “cprofile”) profiler_top_functions: int (default: 50) profiler_sort_by: str (default: “cumulative”) enable_flamegraph: bool (default: True)
- __init__(toolbar)[source]¶
Initialize the panel.
- Parameters:
toolbar (
DebugToolbar) – The parent DebugToolbar instance.
Get the navigation subtitle showing backend.
- Return type:
- class debug_toolbar.core.panels.RequestPanel(toolbar)[source]¶
Panel displaying request details.
Shows: - HTTP method and path - Query parameters - Headers - Cookies - Request body (if available)
Get the navigation subtitle.
- Return type:
- class debug_toolbar.core.panels.ResponsePanel(toolbar)[source]¶
Panel displaying response details.
Shows: - Status code - Response headers - Content type - Content length
Get the navigation subtitle.
- Return type:
- class debug_toolbar.core.panels.SettingsPanel(toolbar, *, custom_settings=None, show_env=True, sensitive_keys=None)[source]¶
Panel displaying application configuration and environment settings.
Shows: - Debug toolbar configuration - Environment variables (with sensitive values redacted) - Python runtime settings - Custom application settings
- Parameters:
-
DEFAULT_SENSITIVE_PATTERNS:
ClassVar[tuple[str,...]] = ('PASSWORD', 'SECRET', 'KEY', 'TOKEN', 'API_KEY', 'AUTH', 'CREDENTIAL', 'PRIVATE')¶
- __init__(toolbar, *, custom_settings=None, show_env=True, sensitive_keys=None)[source]¶
Initialize the settings panel.
- async generate_stats(context)[source]¶
Generate settings statistics.
- Parameters:
context (
RequestContext) – The current request context.- Return type:
- Returns:
Dictionary containing all settings data.
Get the navigation subtitle.
- Return type:
- Returns:
The number of configuration sections.
- class debug_toolbar.core.panels.TemplatesPanel(toolbar)[source]¶
Panel for tracking template rendering performance.
Monitors template renders across multiple engines (Jinja2, Mako) and collects: - Template names - Render times - Template engines used - Context variable names (when available)
The panel patches template engine render methods during the request to capture timing data transparently.
- __init__(toolbar)[source]¶
Initialize the panel.
- Parameters:
toolbar (
DebugToolbar) – The parent DebugToolbar instance.
- async generate_stats(context)[source]¶
Generate template rendering statistics.
- Returns:
renders: List of render events with timing data
total_renders: Total number of templates rendered
total_time: Cumulative render time in seconds
engines_used: List of template engines used
- Return type:
Dictionary containing
Get navigation subtitle showing render count and time.
- Return type:
- async process_request(context)[source]¶
Install template rendering hooks.
Patches Jinja2 and Mako template engines to track renders.
- Return type:
- class debug_toolbar.core.panels.TimerPanel(toolbar)[source]¶
Panel displaying request timing information.
Tracks: - Total request duration - Time spent in various phases - CPU time (user and system)
- __init__(toolbar)[source]¶
Initialize the panel.
- Parameters:
toolbar (
Any) – The parent DebugToolbar instance.
Get the navigation subtitle showing time.
- Return type:
- class debug_toolbar.core.panels.VersionsPanel(toolbar)[source]¶
Panel displaying Python and package version information.
Shows: - Python version - Platform information - Installed packages
Get the navigation subtitle showing Python version.
- Return type:
- class debug_toolbar.core.panels.WebSocketPanel(toolbar)[source]¶
Panel for displaying WebSocket connection and message information.
- classmethod broadcast_message(connection_id, message)[source]¶
Broadcast a message event to live subscribers.
- classmethod broadcast_state_change(connection_id, state, close_code=None)[source]¶
Broadcast a connection state change to live subscribers.
- async generate_stats(context)[source]¶
Generate WebSocket statistics.
- Parameters:
context (
RequestContext) – The current request context.- Return type:
- Returns:
Dictionary containing WebSocket statistics.
- classmethod get_current_stats()[source]¶
Get current WebSocket statistics without a context.
This is used for live updates via WebSocket.
Get the navigation subtitle showing active connection count.
- Return type:
- Returns:
Subtitle string showing active connection count, or empty string.
- classmethod subscribe()[source]¶
Subscribe to live WebSocket panel updates.
- Return type:
Queue[str]- Returns:
An asyncio.Queue that will receive JSON-encoded event messages.
- classmethod track_connection(connection, ttl=3600, max_connections=50)[source]¶
Track a new WebSocket connection.