{"id":16642956,"url":"https://github.com/nir0s/backtrace","last_synced_at":"2025-03-15T12:30:29.835Z","repository":{"id":53791605,"uuid":"73225945","full_name":"nir0s/backtrace","owner":"nir0s","description":"Makes Python tracebacks human friendly","archived":false,"fork":false,"pushed_at":"2020-02-18T10:26:09.000Z","size":1123,"stargazers_count":86,"open_issues_count":12,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T01:24:44.414Z","etag":null,"topics":["backtrace","beautify","exceptions","python","stacktrace","traceback","traceback-entries"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nir0s.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.txt","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-08T20:51:19.000Z","updated_at":"2023-09-08T17:16:53.000Z","dependencies_parsed_at":"2022-09-26T21:50:33.722Z","dependency_job_id":null,"html_url":"https://github.com/nir0s/backtrace","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nir0s%2Fbacktrace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nir0s%2Fbacktrace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nir0s%2Fbacktrace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nir0s%2Fbacktrace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nir0s","download_url":"https://codeload.github.com/nir0s/backtrace/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243730844,"owners_count":20338724,"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":["backtrace","beautify","exceptions","python","stacktrace","traceback","traceback-entries"],"created_at":"2024-10-12T08:07:05.746Z","updated_at":"2025-03-15T12:30:29.462Z","avatar_url":"https://github.com/nir0s.png","language":"Python","readme":"backtrace\n=========\n\nWIP! Untested!\n\n\n[![Travis Build Status](https://travis-ci.org/nir0s/backtrace.svg?branch=master)](https://travis-ci.org/nir0s/backtrace)\n[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/khf9a98rbwp1ehfh/branch/master?svg=true)](https://ci.appveyor.com/project/nir0s/backtrace)\n[![PyPI Version](http://img.shields.io/pypi/v/backtrace.svg)](http://img.shields.io/pypi/v/backtrace.svg)\n[![Supported Python Versions](https://img.shields.io/pypi/pyversions/backtrace.svg)](https://img.shields.io/pypi/pyversions/backtrace.svg)\n[![Requirements Status](https://requires.io/github/nir0s/backtrace/requirements.svg?branch=master)](https://requires.io/github/nir0s/backtrace/requirements/?branch=master)\n[![Code Coverage](https://codecov.io/github/nir0s/backtrace/coverage.svg?branch=master)](https://codecov.io/github/nir0s/backtrace?branch=master)\n[![Code Quality](https://landscape.io/github/nir0s/backtrace/master/landscape.svg?style=flat)](https://landscape.io/github/nir0s/backtrace)\n[![Is Wheel](https://img.shields.io/pypi/wheel/backtrace.svg?style=flat)](https://pypi.python.org/pypi/backtrace)\n\nbacktrace manipulates Python tracebacks to make them more readable.\nIt provides different configuration options for coloring and formatting.\n\nbacktrace also allows to choose the formatting of each part of the traceback; show the traceback entries in reversed order, and more..\n\nExamples:\n\nWhen piping to backtrace:\n\n![Trump? REALLY?! What a nation of idiots!](https://github.com/nir0s/backtrace/raw/master/img/piping.png)\n\nWhen using the API directly from Python:\n\n![Trump? REALLY?! What a nation of idiots!](https://github.com/nir0s/backtrace/raw/master/img/api.png)\n\nNOTE: Didn't test this on Windows yet. Should work.. but don't know how well.\n\n\n## Alternatives\n\n* [colored_traceback](https://github.com/staticshock/colored-traceback.py) provides a way to color your tracebacks to make them more readable. It's a nice little tool but lacks actually re-formatting the traceback which is what the biggest problem is from my POV.\n* Um.. your own implementation? There's really a reason for me doing this. I do have a life you know (well.. I try anyway).\n\n\n## Installation\n\nbacktrace officially supports Linux and OSX on Python 2.7 and 3.4+. Python 2.6 will also probably work, but with no guarantees.\n\n```shell\npip install backtrace\n```\n\nFor dev:\n\n```shell\npip install https://github.com/nir0s/backtrace/archive/master.tar.gz\n```\n\n\n## Usage\n\nbacktrace provides two methods for manipulating your tracebacks.\n\n* Piping to backtrace using its CLI\n* Using backtrace from within your code\n\n### Piping\n\nYou can pipe stderr into backtrace which will try to detect a traceback, parse it and display a beautified trace.\n\n```text\n$ backtrace -h\nusage: backtrace [-h] [-r] [-a] [-s] [-c]\n\nBeautify Tracebacks.\n\nJust pipe stderr into backtrace like so:\n  `python bad-program.py 2\u003e\u00261 | backtrace`\n\noptional arguments:\n  -h, --help          show this help message and exit\n  -r, --reverse       Reverse traceback entry order\n  -a, --align         Right-align the backtrace\n  -s, --strip-path    Strip the path to the module\n  -c, --conservative  Activate conservative mode\n\n$ python my-traceback-generating-program.py 2\u003e\u00261 | backtrace\n...\n\n```\n\n### Inside your application\n\n```python\nimport backtrace\n\nbacktrace.hook(\n    reverse=False,\n    align=False,\n    strip_path=False,\n    enable_on_envvar_only=False,\n    on_tty=False,\n    conservative=False,\n    styles={})\n\n# more code...\n\n# if you wanna restore the default hook...\nbacktrace.unhook()\n...\n\n```\n\nYou can pass the following flags to `hook` to change backtrace's behavior:\n\n* If `reverse` is True, the traceback entries will be printed in reverse order.\n* If `align` is True, all parts (line numbers, file names, etc..) will be\naligned to the left according to the longest entry. This allows for extended readability as your eyes don't have to move between columns to understand what's going on.\n* If `strip_path` is True, only the file name will be shown, not its full\npath. This is useful when you know you're running in the context of a single module or a single package containing only a root folder so you only need file names. This can help keep the traceback clean.\n* If `enable_on_envvar_only` is True, only if the environment variable\n`ENABLE_BACKTRACE` is set, backtrace will be activated.\n* If `on_tty` is True, backtrace will be activated only if you're running\nin a real terminal (i.e. not piped, redirected, etc..). This can help keep the original traceback when logging to files or piping to look for information.\n* `styles` is a dictionary containing the styling for each part of the rebuilt traceback. See below.\n* If `conservative` is true, a more conservative format will be provided for people who find the default backtrace style too new or intimidating. For example, no alignment will be done (unless `align` is explicitly passed), `styles` will be ignored, and potential unnecessary data will be retained. Try It! It's still eye-candy.\n\n#### Styles\n\nStyles allow you to customize the coloring and structure of your new traceback. The defaults are:\n\n```python\nSTYLES = {\n    'backtrace': Fore.YELLOW + '{0}',\n    'error': Fore.RED + Style.BRIGHT + '{0}',\n    'line': Fore.RED + Style.BRIGHT + '{0}',\n    'module': '{0}',\n    'context': Style.BRIGHT + Fore.GREEN + '{0}',\n    'call': Fore.YELLOW + '--\u003e ' + Style.BRIGHT + '{0}',\n}\n```\n\nWhere:\n\n* `backtrace` is the main traceback message.\n* `error` is the error message presenting the exception message and its type.\n* `line` is the line number of each entry.\n* `module` is the calling module of each entry.\n* `context` is the calling function/method of each entry.\n* `call` is the called function/method/assignment of each entry.\n\nand the `{0}` format place holder is the actual value of the field.\n\nSending a partial dictionary containing changes in only some parts of the traceback will have `backtrace` use the defaults for whatever wasn't specified.\n\nYou can do all sorts of stuff like removing a certain field by setting the formatting of that field to an empty string; add more verbose identifiers to each field by appending an ID in front of it or just adding paranthese around a field.\n\n\n## Coloring\n\nColoring is powered by [colorama](https://github.com/tartley/colorama).\n\n\n## Testing\n\nTo see an example printout:\n\n```shell\n$ python test.py\n```\n\n```shell\ngit clone git@github.com:nir0s/backtrace.git\ncd backtrace\npip install tox\ntox\n```\n\n## Contributions..\n\nSee [CONTRIBUTIONS](https://github.com/nir0s/backtrace/blob/master/CONTRIBUTING.md)\n\nPull requests are always welcome..\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnir0s%2Fbacktrace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnir0s%2Fbacktrace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnir0s%2Fbacktrace/lists"}