Skip to main content

A tiny (nearly) 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.1.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.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zdbg-1.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 96ea3aef27dfe2d46b69eb09581b606385dcdba4bb3ac6b178b6fc5f8f93d651
MD5 66f814893c6f29e7a60cc62950e4a2c4
BLAKE2b-256 a0ee6ec57961dc38aa28a566dbdb9fbd79013e267d5934dfac35ef17a7623104

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zdbg-1.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d257cc2baea254151de4bb7bb593094dd2b79b83ced1965d7bfd922849e69f8
MD5 c649781c8b501e0989251bc5b37d5d94
BLAKE2b-256 ff6307960fa956aceb8c191de369added35a9bf43c1e16c0252ee8edccb6864c

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