Skip to main content

About backlash

https://github.com/TurboGears/backlash/actions/workflows/run_tests.yml/badge.svg https://img.shields.io/pypi/v/backlash.svg

backlash is a swiss army knife for web applications debugging, which provides:

  • An Interactive In Browser Debugger for WSGI and ASGI applications, based on a Werkzeug Debugger fork

  • Crash reporting by email and on Sentry (WSGI)

  • Slow requests reporting by email and on Sentry (WSGI).

Backlash was born as a replacement for WebError in TurboGears2.3 versions.

Installing

backlash can be installed from pypi:

pip install backlash

should just work for most of the users. backlash has no runtime dependencies.

Debugging and Console

Backlash supports both debugging applications on crash and realtime console, both based on the Werkzeug Debugger.

The debugging function is provided by the WsgiDebuggedApplication middleware for WSGI applications and the AsgiDebuggedApplication middleware for ASGI applications (Starlette, FastAPI, bare ASGI apps). Wrapping your application with the middleware will intercept any exception and display the traceback and an interactive console in your browser.

An interactive console will also be always available at /__console__ path.

backlash.DebuggedApplication (importable also as backlash.debug.DebuggedApplication) is the same class as backlash.wsgi.WsgiDebuggedApplication, so existing WSGI setups keep working unchanged.

ASGI Applications

Bare ASGI applications are wrapped directly:

from backlash.asgi import AsgiDebuggedApplication

app = AsgiDebuggedApplication(app)

Starlette and FastAPI applications should install the debugger with add_middleware instead of wrapping the application object:

app.add_middleware(AsgiDebuggedApplication)

This places the debugger inside Starlette’s ServerErrorMiddleware, which otherwise sends its own 500 response before re-raising, leaving the debugger no chance to render its page.

Context Injectors

The debugger middlewares also make possible to provide one or more context injectors, those are simple python functions that will be called when an exception is raised to retrieve the context to store and make back available during debugging. Context injectors receive the WSGI environ or the ASGI scope of the failed request.

Context injectors have to return a dictionary which will be merged into the current request context, the request context itself will be made available inside the debugger as the ctx object.

This feature is used for example by TurboGears to provide back some of the objects which were available during execution like the current request.

Example

The DebuggedApplication middleware is used by TurboGears in the following way:

def _turbogears_backlash_context(environ):
    tgl = environ.get('tg.locals')
    return {'request':getattr(tgl, 'request', None)}

app = backlash.DebuggedApplication(app, context_injectors=[_turbogears_backlash_context])

Exception Tracing

The TraceErrorsMiddleware provides a WSGI middleware that intercepts any exception raised during execution, retrieves a traceback object and provides it to one or more reporters to log the error.

By default the EmailReporter and SentryReporter are provided to send error reports by email and on Sentry.

The EmailReporter supports most of the options WebError ErrorMiddleware to provide some kind of backward compatibility and make possible a quick transition.

While this function is easily replicable using the python logging SMTPHandler, the TraceErrorsMiddleware is explicitly meant for web applications crash reporting which has the benefit of being able to provide more complete information and keep a clear and separate process in managing errors.

Example

The TraceErrorsMiddleware is used by TurboGears in the following way:

from backlash.trace_errors import EmailReporter

def _turbogears_backlash_context(environ):
   tgl = environ.get('tg.locals')
   return {'request':getattr(tgl, 'request', None)}

app = backlash.TraceErrorsMiddleware(app, [EmailReporter(**errorware)],
                                     context_injectors=[_turbogears_backlash_context])

Slow Requests Tracing

The TraceSlowRequestsMiddleware provides a WSGI middleware that tracks requests execution time and reports requests that took more than a specified interval to complete (by default 25 seconds).

It is also possible to exclude a list of paths that start with a specified string to avoid reporting long polling connections or other kind of requests that are expected to have a long life spawn.

Example

The TraceSlowRequestsMiddleware is used by TurboGears in the following way:

from backlash.trace_errors import EmailReporter

def _turbogears_backlash_context(environ):
   tgl = environ.get('tg.locals')
   return {'request':getattr(tgl, 'request', None)}

app = backlash.TraceSlowRequestsMiddleware(app, [EmailReporter(**errorware)],
                                           interval=25, exclude_paths=None,
                                           context_injectors=[_turbogears_backlash_context])

Release files for backlash 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for backlash 0.5.1
File Size Uploaded
backlash-0.5.1.tar.gz 191.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for backlash 0.5.1
File Interpreter ABI Platform
backlash-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 375.7 kB

Release files / backlash-0.5.1.tar.gz

Download URL backlash-0.5.1.tar.gz
Size 191.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7721245a87a8c68b743ea9c63b803bdfde0c8db601580bd980a08736cbe5b583
BLAKE2b-256 checksum
How to use checksums
8c92e479b19118cad8be94fa9c29cd9c0c6f26c7bec938c99141eb96f40012a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / backlash-0.5.1-py3-none-any.whl

Download URL backlash-0.5.1-py3-none-any.whl
Size 184.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa669c9c213d55573b9ad2dba40587f9caa82abdeca808b6a243b2ae56ef3395
BLAKE2b-256 checksum
How to use checksums
466eabfd30386063e5e7c3608283c75b2367d208c5aacfa69b4c1ef42922cdb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page