Skip to main content

A tiny zero-cost debugging helper for Python

Project description

zdbg

A (nearly) zero-cost library for printing debugging and error messages from Python programs that is trivial to use, while also giving you the following.

  • Per-stream output selection (errors and debugging messages).
  • Color-tagged labels.
  • Optional timestamps and file context information.
  • Zero-cost disable path (via rebinding debug to a no-op).
  • Atomic thread-safe reconfiguration.
  • Optional stream flush behavior.
  • No handler objects, logger objects, format strings, or logger factories.
  • A single configure() function determining all output behavior.
  • NO additional dependencies beyond the standard Python libraries.

How simple is zdbg to use? The following is an example.

import zdbg

if __name__ == "__main__":
    zdbg.debug("Starting")
    zdbg.error("Nothing to do")
    zdbg.debug("Stopping")

Put the above in ztest.py and then try the following.

$ python3 ./ztest.py
Error: Nothing to do

$ DEBUG=debug python3 ./ztest.py
DEBUG: Starting
Error: Nothing to do
DEBUG: Stopping

$ DEBUG=debug,context python3 ./ztest.py
DEBUG: ./ztest.py:8: Starting
Error: ./ztest.py:9: Nothing to do
DEBUG: ./ztest.py:10: Stopping

Screenshot of shell interaction

The format of the error context string makes it clickable in many tools, including Visual Studio Code.

Why zdbg

I wanted something simple with zero overhead when debugging is disabled, without other dependencies, and with configurability without having to do a lot of work up front to get things working.

If that sounds good, then Welcome!

zdbg uses Semantic Versioning.

Performance

"Zero cost?" Well... of course not. But as close to that as I think we can get while still having runtime configurability. See the perftest.py script in examples for a simple performance test that shows the relative overhead of different debugging strategies.

Documentation

See the full documentation of zdbg in the docstring for the module, or USAGE.md

Bugs?

Have you found a bug? Submit it through the zdbg Issues tracker, and be sure to include (1) what happens, (2) what you expect to happen, (3) how to reproduce the bug, and (4) what version of zdbg you are using.

Minimum Supported Python Version

See pyproject.toml.

Security

Please submit sensitive security issues using the "This issue is confidential..." button below the issue description field in the issue tracker.

Contribute

See CONTRIBUTING.md for information about contributing to this project.

Copyright

zdbg is Copyright (c) by Stacy Prowell mailto:sprowell+zdbg@gmail.com. All rights reserved. See the LICENSE file for more information.

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

zdbg-1.1.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zdbg-1.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file zdbg-1.1.0.tar.gz.

File metadata

  • Download URL: zdbg-1.1.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for zdbg-1.1.0.tar.gz
Algorithm Hash digest
SHA256 b07cf92b4375c6c9dcbf8c4d7b14b7b5522bea4db7e6cb5d241614f3c0044680
MD5 6532c74921c6769e237b306980fe0380
BLAKE2b-256 d5a12b8f1897b304a040e7cd33f743cf112e63ed98816e69d6b307d3b79d536d

See more details on using hashes here.

File details

Details for the file zdbg-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: zdbg-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for zdbg-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ae6650bc706ed3fd724e99cedddf6434777cba906f635357ba5d81b3d5cef38
MD5 91862bf65341ae4c1ef38675f51e0e3a
BLAKE2b-256 433fe10853803c66186e03a01ff8beb7762c85817ff8c804854a1ed404952d92

See more details on using hashes here.

Supported by

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