{"id":13617242,"url":"https://github.com/skorokithakis/tbvaccine","last_synced_at":"2025-04-04T11:09:42.939Z","repository":{"id":57473594,"uuid":"66727160","full_name":"skorokithakis/tbvaccine","owner":"skorokithakis","description":"A small utility to pretty-print Python tracebacks. ⛺","archived":false,"fork":false,"pushed_at":"2020-03-01T19:24:46.000Z","size":807,"stargazers_count":377,"open_issues_count":7,"forks_count":14,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-14T13:01:51.099Z","etag":null,"topics":["error-handling","python","traceback"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skorokithakis.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-27T17:31:59.000Z","updated_at":"2024-08-19T20:13:43.000Z","dependencies_parsed_at":"2022-09-26T17:40:55.961Z","dependency_job_id":null,"html_url":"https://github.com/skorokithakis/tbvaccine","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skorokithakis%2Ftbvaccine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skorokithakis%2Ftbvaccine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skorokithakis%2Ftbvaccine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skorokithakis%2Ftbvaccine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skorokithakis","download_url":"https://codeload.github.com/skorokithakis/tbvaccine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166144,"owners_count":20894652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["error-handling","python","traceback"],"created_at":"2024-08-01T20:01:38.956Z","updated_at":"2025-04-04T11:09:42.915Z","avatar_url":"https://github.com/skorokithakis.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"TBVaccine\n---------\n\n.. image:: https://www.codeshelter.co/static/badges/badge-flat.svg\n    :target: https://www.codeshelter.co\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/ambv/black\n\nTBVaccine is a utility that pretty-prints Python tracebacks. It automatically\nhighlights lines you care about and deemphasizes lines you don't, and colorizes\nthe various elements in a traceback to make it easier to parse.\n\nHere are some screenshots. This is the before:\n\n.. image:: misc/before.png\n\nAnd this is the after:\n\n.. image:: misc/after.png\n\nIf you add the hook or call TBVaccine in your code, it can also print all\nvariables in each stack frame. That is, it turns this:\n\n.. image:: misc/before-vars.png\n\ninto this:\n\n.. image:: misc/after-vars.png\n\n\nInstallation\n============\n\nTo install, use ``pip``::\n\n    pip install tbvaccine\n\nYou are done!\n\n\nGlobal usage\n============\n\nYou can have TBVaccine insert itself all up in your system and stick its tentacles in\nall your libraries, like a cute, useful Cthulhu. That way, every single Python\ntraceback in your system will be pretty. Just set the `TBVACCINE` environment\nvariable to 1, and you're done.\n\nE.g. for bash::\n\n    export TBVACCINE=1\n\nOr fish::\n\n    set -x TBVACCINE=1\n\nIf you want to prettify tracebacks even when stderr is not a tty, set\n`TBVACCINE_FORCE` to 1::\n\n    export TBVACCINE=1\n    export TBVACCINE_FORCE=1\n    python -c '1/0' 2\u003e\u00261 | cat  # pretty!\n\nNOTE: If you're on Ubuntu, you most likely have Apport installed, which overrides\nTBVaccine's hook with its own. To disable Apport for Python, delete a file named\n``/etc/python\u003cversion\u003e/sitecustomize.py``. Note that this will disable Apport for\nPython, and you won't be asked to submit info to Ubuntu when Python programs crash\nany more. For some, this is a good thing.\n\n\nUsage as a command-line utility\n===============================\n\nTBVaccine can be used from the command line several ways.::\n\n    python -m tbvaccine myscript.py\n\nOr just pipe STDERR into it from the program you want to watch::\n\n    ./myscript.py 2\u003e\u00261 | tbvaccine\n\nAnd all the tracebacks will now be pretty!\n\n\nUsage as a Python library\n=========================\n\nThere are various ways to use TBVaccine as a Python library.\n\nInitialize it like so::\n\n    from tbvaccine import TBVaccine\n    tbv = TBVaccine(\n        code_dir=\"/my/code/dir\",\n        isolate=True\n    )\n\n``code_dir`` marks the directory we code about. Files under that directory that\nappear in the traceback will be highlighted. If not passed, the current\ndirectory, as returned by ``os.getcwd()`` will be used.\n\nIf ``isolate`` is ``False``, all lines are colorized, and ``code_dir`` is\nignored.\n\nIf ``show_vars`` is ``False``, variables will not be printed in each stack\nframe.\n\nTo use it in an ``except`` block::\n\n    from tbvaccine import TBVaccine\n    try:\n        some_stuff()\n    except:\n        print(TBVaccine().format_exc())\n\n\nTo make it the default way of printing tracebacks, use ``add_hook()`` (which\nalso accepts any argument the ``TBVaccine`` class does)::\n\n    import tbvaccine\n    tbvaccine.add_hook(isolate=False)\n\n    1 / 0\n\nBam! Instant pretty tracebacks.\n\n\nLogging integration\n===================\n\nYou can integrate TBVaccine with logging like so::\n\n    class TbVaccineFormatter(logging.Formatter):\n        def  formatException(self, exc_info):\n            return TBVaccine(isolate=True).format_exc()\n\n    sh = logging.StreamHandler()\n    sh.setFormatter(TbVaccineFormatter('[%(levelname)s] %(asctime)s : %(message)s', '%Y-%m-%d %H:%M:%S'))\n    logger.addHandler(sh)\n\n\nConfiguration\n=============\n\nTo configure TBVaccine, open its configuration file in ``~/.config/tbvaccine/tbvaccine.cfg`` (or your\noperating system's equivalent) and edit it. You can currently configure the color style there by\nspecifying one of the `Pygments styles \u003chttp://pygments.org/demo/6778888/?style=monokai\u003e`.\n\n\nEpilogue\n========\n\nThis library is still pretty new, please contribute patches if something doesn't\nwork as intended, and also please tell your friends about it! Hopefully one day\nit will be implemented in the Python interpreters themselves.\n\n-- Stavros\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskorokithakis%2Ftbvaccine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskorokithakis%2Ftbvaccine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskorokithakis%2Ftbvaccine/lists"}