pyramid_debugtoolbar API

pyramid_debugtoolbar.includeme(config)

Activate the debug toolbar.

Usually called via config.include('pyramid_debugtoolbar') instead of being invoked directly.

pyramid_debugtoolbar.toolbar_tween_factory(handler, registry, _logger=None, _dispatch=None)

Pyramid tween factory for the debug toolbar

pyramid_debugtoolbar.toolbar_app.add_debugtoolbar_panel(config, panel_class, is_global=False)

Register a new panel into the debugtoolbar.

This is a Pyramid config directive that is accessible as config.add_debugtoolbar_panel within the debugtoolbar application. It should be used from includeme functions via the debugtoolbar.includes setting.

The panel_class should be a subclass of pyramid_debugtoolbar.panels.DebugPanel.

If is_global is True then the panel will be added to the global panel list which includes application-wide panels that do not depend on per-request data to operate.

pyramid_debugtoolbar.toolbar_app.inject_parent_action(config, action)

Inject an action into the parent application.

This is a Pyramid config directive that is accessible as config.inject_parent_action within the debugtoolbar application. It should be used from includeme functions via the debugtoolbar.includes setting.

The action should be a callable that accepts the parent app's config object. It will be executed after the parent app is created to ensure that configuration is set prior to the actions being executed.

class pyramid_debugtoolbar.panels.DebugPanel(request)

Base class for debug panels. A new instance of this class is created for every request.

A panel is notified of events throughout the request lifecycle. It is then persisted and used later by the toolbar to render its results as a tab on the interface. The lifecycle hooks are available in the following order:

Each of these hooks is overridable by a subclass to gleen information from the request and other events for later display.

The panel is later used to render its results. This is done on-demand and in the lifecycle of a request to the debug toolbar by invoking render_content(). Any data stored within data is injected into the template prior to rendering and is thus a common location to store the contents of previous events.

__init__(request)

Configure the panel for a request.

Parameters:

request -- The instance of pyramid.request.Request that this object is wrapping.

data

A dictionary of data, updated during the request lifecycle, and later used to render the panel's HTML.

property dom_id

The id tag of the panel's tab. May be used by CSS and Javascript to implement custom styles and actions.

By default, the dom_id for a panel with a name of 'performance' will be 'pDebugPanel-performance'.

has_content = False

If False then the panel's tab will be disabled and render_content() will not be invoked. Most subclasses will want to set this to True.

is_active = False

This property will be set by the toolbar, indicating the user's decision to activate or deactivate the panel. If user_activate is False then is_active will always be set to True.

name = NotImplemented

A unique identifier for the name of the panel. This must be defined by a subclass and be a valid Python variable name (something like [a-zA-Z0-9_-]+).

nav_subtitle = ''

Subtitle showing until title in toolbar.

nav_subtitle_style = ''

CSS class used to give the subtitle a background color.

nav_title = NotImplemented

Title showing in toolbar. Must be overridden.

process_beforerender(event)

Receives every pyramid.events.BeforeRender event invoked during the request/response lifecycle of the request.

Override this method to track properties of the rendering events.

process_response(response)

Receives the response generated by the request.

Override this method to track properties of the response.

render_content(request)

Return a string containing the HTML to be rendered for the panel.

By default this will render the template defined by the template attribute with a rendering context defined by data combined with the dict returned from render_vars().

The request here is the active request in the toolbar. Not the original request that this panel represents.

render_vars(request)

Invoked by the default implementation of render_content() and should return a dict of values to use when rendering the panel's HTML content. This value is usually injected into templates as the rendering context.

The request here is the active request in the toolbar. Not the original request that this panel represents.

template = NotImplemented

Must be overridden by subclasses that are using the default implementation of render_content. This is an asset specification pointing at the template to be rendered for the panel. Usually of the format 'mylib:templates/panel.dbtmako'.

title = NotImplemented

Title showing in panel. Must be overridden.

url = ''

The URL invoked when the panel's tab is cliked. May be overridden to define an arbitrary URL for the panel or do some other custom action when the user clicks on the panel's tab in the toolbar.

user_activate = False

If the client is able to activate/de-activate the panel then this should be True.

wrap_handler(handler)

May be overridden to monitor the entire lifecycle of the request.

A handler receives a request and returns a response. An example implementation may be:

def wrap_handler(self, handler):
    def wrapper(request):
        start_time = time.monotonic()
        response = handler(request)
        end_time = time.monotonic()
        self.data['duration'] = end_time - start_time
        return response
    return wrapper
class pyramid_debugtoolbar.panels.sqla.SQLADebugPanel(request)

Panel that displays the SQL generated by SQLAlchemy plus the time each SQL statement took in milliseconds.

class pyramid_debugtoolbar.panels.versions.VersionDebugPanel(request)

Panel that displays the Python version, the Pyramid version, and the versions of other software on your PYTHONPATH.

class pyramid_debugtoolbar.panels.settings.SettingsDebugPanel(request)

A panel to display Pyramid deployment settings for your application (the values in registry.settings).

class pyramid_debugtoolbar.panels.routes.RoutesDebugPanel(request)

A panel to display the routes used by your Pyramid application.

class pyramid_debugtoolbar.panels.request_vars.RequestVarsDebugPanel(request)

A panel to display request variables (POST/GET, cookies, and ad-hoc request attributes).

class pyramid_debugtoolbar.panels.renderings.RenderingsDebugPanel(request)

Panel that displays the renderers (templates and 'static' renderers such as JSON) used during a request.

class pyramid_debugtoolbar.panels.performance.PerformanceDebugPanel(request)

Panel that looks at the performance of a request.

It will display the time a request took and, optionally, the cProfile output.

class pyramid_debugtoolbar.panels.logger.LoggingPanel(request)
class pyramid_debugtoolbar.panels.headers.HeaderDebugPanel(request)

A panel to display HTTP request and response headers.