Skip to main content

A utility that cures the horrible traceback displays in Python, making them more readable.

Project description

TBVaccine is a utility that pretty-prints Python tracebacks. It automatically highlights lines you care about and deemphasizes lines you don’t, and colorizes the various elements in a traceback to make it easier to parse.

Here are some screenshots. This is the before:

misc/before.png

And this is the after:

misc/after.png

If you add the hook or call TBVaccine in your code, it can also print all variables in each stack frame. That is, it turns this:

misc/before-vars.png

into this:

misc/after-vars.png

Installation

To install, use pip:

pip install tbvaccine

You are done!

Global usage

You can have TBVaccine insert itself all up in your system and stick its tentacles in all your libraries, like a cute, useful Cthulhu. That way, every single Python traceback in your system will be pretty. Just set the TBVACCINE environment variable to 1, and you’re done.

E.g. for bash:

export TBVACCINE=1

Or fish:

set -x TBVACCINE=1

Usage as a command-line utility

TBVaccine can be used from the command line several ways.:

python -m tbvaccine myscript.py

Or just pipe STDERR into it from the program you want to watch:

./myscript.py 2>&1 | tbvaccine

And all the tracebacks will now be pretty!

Usage as a Python library

There are various ways to use TBVaccine as a Python library.

Initialize it like so:

from tbvaccine import TBVaccine
tbv = TBVaccine(
    code_dir="/my/code/dir",
    isolate=True
)

code_dir marks the directory we code about. Files under that directory that appear in the traceback will be highlighted. If not passed, the current directory, as returned by os.getcwd() will be used.

If isolate is False, all lines are colorized, and code_dir is ignored.

If show_vars is False, variables will not be printed in each stack frame.

To use it in an except block:

from tbvaccine import TBVaccine
try:
    some_stuff()
except:
    print(TBVaccine().format_exc())

To make it the default way of printing tracebacks, use add_hook() (which also accepts any argument the TBVaccine class does):

import tbvaccine
tbvaccine.add_hook(isolate=False)

1 / 0

Bam! Instant pretty tracebacks.

Epilogue

This library is still pretty new, please contribute patches if something doesn’t work as intended, and also please tell your friends about it! Hopefully one day it will be implemented in the Python interpreters themselves.

– Stavros

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

tbvaccine-0.2.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

tbvaccine-0.2.2-py2-none-any.whl (10.0 kB view details)

Uploaded Python 2

File details

Details for the file tbvaccine-0.2.2.tar.gz.

File metadata

  • Download URL: tbvaccine-0.2.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tbvaccine-0.2.2.tar.gz
Algorithm Hash digest
SHA256 083b1ffd9e547e27c7d74fac4ad169f679a5f0ad499d1800e3743697f825b0eb
MD5 e9978cf6c594139dac0fc1eafda8b96a
BLAKE2b-256 657512b88d29caffcc12a9f1035ebdc626ebdded3ce64310db272ffe3443c581

See more details on using hashes here.

File details

Details for the file tbvaccine-0.2.2-py2-none-any.whl.

File metadata

File hashes

Hashes for tbvaccine-0.2.2-py2-none-any.whl
Algorithm Hash digest
SHA256 a6ec99b16a9a7204e0c522c18b28bfdb44e891295d931e3e88c5a4b17871dc19
MD5 8fa534864c71636ca516e3956803c14b
BLAKE2b-256 ad68af2fdc13122bde84e81af1b306915bcacf6eafb7b1be0f4466615f6dfc74

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