Skip to main content

Debug Tools for py4web

Project description

py4web debug tools

Tooling to improve the developer experience when working with py4web.

There are two main tools and some helpers that this package provides.

  1. A better error 500 screen, that shows the error + traceback of what happened
  2. A debug bar containing the requests's data, queries including duplicate and custom caught data.

In this package:

  • tools:
    • enable(db: DAL, enabled?: bool, errorpage_enabled?: bool, errorpage_renderer?: Callable, debugbar_enabled?: bool, debugbar_fancy_rendering?: bool, debugbar_style?: "bootstrap", debugbar_slow_threshold_ms?: int, set_env_var?: bool):
      activate or disable the debug tools (add the custom error screen and create the Debug Bar Fixture).
      The first argument (DAL) is required for the debug bar to collect queries.
      enabled can be used to dynamically turn on/off the debug features.
      errorpage_enabled and debugbar_enabled can be used to turn on/off the error page and debug bar respectively.
      errorpage_renderer can be used to override the default error page renderer.
      debugbar_fancy_rendering: This will render the data section of the debug bar using json-browse, which includes jQuery. If this clashes with the other JS on a page, this can be set to False to simply show a <pre> block with data.
      debugbar_style: only bootstrap is supported at this moment.
      debugbar_slow_threshold_ms: amount of milliseconds an SQL query has to take before it is considered a 'slow query' in the debug bar.
      set_env_var: set the PY4WEB_DEBUG environment variable to True when enabling the debug tools.
    • debug_bar: this Fixture can be used on py4web actions to enable the bar for that page.
  • catch(*): Data and a stacktrace of where catch() is called can be found in the catch tab of the debug bar.
  • dump(*): convert objects to JSON, with a more capable converter than the default json.dumps (e.g. it works better with NamedTuples, pyDAL Rows, objects with some variation of as_dict and more. See dumping.py:DDJsonEncoder for specifics)
  • dd(*): Show a page with the data passed to this method and halt execution directly.
  • wsgi: a patched version of py4web's wsgi module, that will enable the modified error page.

Example:

# controllers.py

from py4web_debug import tools, catch, dump, dd

tools.enable(db, enabled=True)


@action("index")
@action.uses("index.html", db, tools.debug_bar)
def index():
    catch("Catch to Debug Bar")
    return {}


@action("other")
@action.uses("index.html", db)
def page_without_debugbar():
    dd("Stop executing here!")
    return {}


@action("error")
@action.uses("index.html", db)
def page_with_error():
    0 / 0
    return {}

Caveats:

When using uwsgi, the default method (in __init__) of changing py4web's catch_errors will not work. This is because the routes are set up before this package can be enabled. You can modify your py4web_uwsgi.py file:

# no: from py4web.core import wsgi
# yes:
from py4web_debug import wsgi

application = wsgi(apps_folder="apps",
                   password_file='password.txt',
                   dashboard_mode="full")

After this, you can tools.enable as before. Do note this process will keep py4web patched though, even when enable(enabled=False) is passed!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py4web_debug_tools-1.1.1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

py4web_debug_tools-1.1.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file py4web_debug_tools-1.1.1.tar.gz.

File metadata

  • Download URL: py4web_debug_tools-1.1.1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.1

File hashes

Hashes for py4web_debug_tools-1.1.1.tar.gz
Algorithm Hash digest
SHA256 401d0b672b3980daaa0599570fc1bda8e802c8568497b389e5556f102d5a874f
MD5 ac3a389940cc4da4c657a86df82fc7ba
BLAKE2b-256 037edab4a892654cc2ac1970a0e6c1f3e559e87198b04d35fa8c28aa65aabe1f

See more details on using hashes here.

File details

Details for the file py4web_debug_tools-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for py4web_debug_tools-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 742e03b20735542b84963b4d804dba1fba57f67fead064a7a31b2590307e6225
MD5 ef420d1935985a12769ac5c80203d5b4
BLAKE2b-256 55fcec45f409a64ec69cbee34f3bfdce7ecadd24fc9116462d2137c9638a0362

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page