debug_toolbar.core.storage

Storage backend for toolbar request history using LRU cache.

Classes

FileToolbarStorage(file_path[, max_size])

File-backed storage for sharing data between processes.

ToolbarStorage([max_size])

Thread-safe LRU storage for toolbar request history.

class debug_toolbar.core.storage.ToolbarStorage(max_size=50)[source]

Thread-safe LRU storage for toolbar request history.

This storage maintains a bounded history of request data, automatically evicting the oldest entries when the maximum size is reached.

max_size

Maximum number of requests to store.

__init__(max_size=50)[source]

Initialize the storage.

Parameters:

max_size (int) – Maximum number of requests to store. Defaults to 50.

max_size
store(request_id, data)[source]

Store request data.

Parameters:
  • request_id (UUID) – Unique identifier for the request.

  • data (dict[str, Any]) – Dictionary of data to store.

Return type:

None

get(request_id)[source]

Retrieve request data.

Parameters:

request_id (UUID) – Unique identifier for the request.

Return type:

dict[str, Any] | None

Returns:

The stored data, or None if not found.

get_all()[source]

Get all stored requests.

Return type:

list[tuple[UUID, dict[str, Any]]]

Returns:

List of (request_id, data) tuples, newest first.

clear()[source]

Clear all stored requests.

Return type:

None

store_from_context(context)[source]

Store data from a request context.

Parameters:

context (RequestContext) – The RequestContext to store.

Return type:

None

class debug_toolbar.core.storage.FileToolbarStorage(file_path, max_size=50)[source]

File-backed storage for sharing data between processes.

Extends ToolbarStorage to persist data to a JSON file, enabling the web app and MCP server to share request history.

file_path

Path to the JSON storage file.

__init__(file_path, max_size=50)[source]

Initialize file-backed storage.

Parameters:
  • file_path (str | Path) – Path to the JSON file for persistence.

  • max_size (int) – Maximum number of requests to store. Defaults to 50.

file_path
store(request_id, data)[source]

Store request data and persist to file.

Return type:

None

clear()[source]

Clear all stored requests and the file.

Return type:

None

reload()[source]

Reload data from file (useful for MCP server to get fresh data).

Return type:

None

get(request_id)[source]

Retrieve request data, reloading from file first.

Return type:

dict[str, Any] | None

get_all()[source]

Get all stored requests, reloading from file first.

Return type:

list[tuple[UUID, dict[str, Any]]]