Skip to main content

py-ndebug

Tiny python debugging utility modeled after visionmedia's node.js debug module and the python 3 print function.

CircleCI PyPI version

Installation

$ pip install ndebug

Usage

With create you simply invoke the exported function to generate your debug function, passing it a name which will determine if a noop function is returned, or custom decorated function that emulates the python 3 print function but, by default, prints to sys.stderr. A unique color is selected per-function for visibility.

Example test.py:

import ndebug
import time

# 
# ndebug.create(name)
#
# once you have initialized the debug module you can call it as shown below
#
# debug(*objects, sep=' ', end='\n', file=sys.stderr, flush=False)
#

debug = ndebug.create("test")
debug("hi there2")

debug2 = ndebug.create("test2")
debug2("awesome")

debug({"awesome": True}, True, 1, "test")
debug([], {1,2,3}, {"awesome": True}, True, 1, "test")

time.sleep(0.1)
debug('should be milliseconds now')

time.sleep(1)
debug('should be seconds now')

The DEBUG environment variable is then used to enable these based on space or comma-delimited names. Here are some examples:

$ DEBUG=* python -m examples
$ DEBUG=examples:test1 python -m examples
$ DEBUG=examples:test2 python -m examples
$ DEBUG=examples:* python -m examples

Microsecond diff

When actively developing an application it can be useful to see when the time spent between one debug() call and the next. Suppose for example you invoke debug() before requesting a resource, and after as well, the "+NNNus" will show you how much time was spent between calls.

When File is not a TTY

When the file is not a TTY, to_utc_string() is called which mimicks the default behavior of the Javascript Date#toUTCString() method used in the node.js debug module, making it more useful for logging the debug information as shown below

$ DEBUG=* python -m examples 2>&1 | grep test
$ DEBUG=* python -m examples 2>&1 | grep test2

Conventions

If you're using this in one or more of your libraries, you should use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you should prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser".

Wildcards

The "*" character may be used as a wildcard. Suppose for example your library has debuggers named "connect:bodyParser", "connect:compress", "connect:session", instead of listing all three with DEBUG=connect:bodyParser,connect.compress,connect:session, you may simply do DEBUG=connect:*, or to run everything using this module simply use DEBUG=*.

You can also exclude specific debuggers by prefixing them with a "-" character or whitespace. For example:

$ DEBUG=examples:*,-examples:test1 python -m examples

License

The MIT License (MIT)

Copyright (c) 2013 Malcom Gilbert Copyright (c) 2019 Peter Magnusson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for ndebug 0.1.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 ndebug 0.1.1
File Size Uploaded Provenance Actions
ndebug-0.1.1.tar.gz 5.8 kB Without provenance Details for ndebug-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 12.5 kB

Release files / ndebug-0.1.1.tar.gz

Download URL ndebug-0.1.1.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6bbaa5f88216959eb4fcb75ec4344ff3d01e13c73f771258ee283a07c9864013
BLAKE2b-256 checksum
How to use checksums
102b91c37f9031e34dc21d841347ebdcd298fa156c0a2c55a5363abd5a0d5447
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.1

Release files / ndebug-0.1.1-py3-none-any.whl

Download URL ndebug-0.1.1-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc286b22d983e4e05dab3485852c5d0bc642689d246591be4284b3cd5ef2896e
BLAKE2b-256 checksum
How to use checksums
5f6e6310533e6be96c746ca9dad6ebe1a9a87e96d809614533a36ea3ac2c22ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.1

Security for ndebug 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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