Registry / testing / pretty-errors

pretty-errors

JSON →
library1.2.25pypypi✓ verified 87d ago

PrettyErrors is a Python library designed to make Python exception output more legible and user-friendly. It provides color coding, simplifies tracebacks, and categorizes errors, making it easier for developers to understand what went wrong and how to fix it. The current version is 1.2.25. Its release cadence is irregular, with updates typically driven by new features or bug fixes rather than a strict schedule.

pip install pretty_errors
INSTALL
IMPORT
SIG · PRETTY-ERRORS
P
pretty-errors
testingpythonv1.2.25
Install
1.6s avg
Import
20ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.25 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.014s · 18.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.026s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pretty_errors
import pretty_errors
This import activates PrettyErrors for runtime exceptions within the current script. For universal activation (including SyntaxErrors), it is recommended to run 'python -m pretty_errors' once.

This quickstart demonstrates how to import and optionally configure `pretty_errors` to format exception output. It then triggers a `ZeroDivisionError` to show the prettified traceback. For universal activation across all Python runs (including `SyntaxError`), run `python -m pretty_errors` in your terminal once after installation.

import pretty_errors # Optional: Configure pretty_errors for customized output pretty_errors.configure( separator_character = '#', filename_display = pretty_errors.FILENAME_EXTENDED, line_number_first = True, display_link = True, lines_before = 3, lines_after = 2, line_color = pretty_errors.RED + '> ' + pretty_errors.default_config.line_color, code_color = ' ' + pretty_errors.default_config.line_color, truncate_code = True, display_locals = True ) def calculate_division(numerator, denominator): return numerator / denominator # This will intentionally cause a ZeroDivisionError print(calculate_division(10, 0))
pretty_errors --version
Debug
Known issues
gotchaPrettyErrors requires a terminal capable of color output to display colored exceptions effectively. On Windows, this means using PowerShell, Cmder, or similar; the standard `cmd.exe` may not render colors correctly.
fix
Use a terminal emulator that supports ANSI color codes. If a monochrome terminal is necessary, call `pretty_errors.mono()` after importing `pretty_errors` to optimize output for it, or configure colors manually to be empty strings.
affects: All versions
gotchaManually importing `pretty_errors` (e.g., `import pretty_errors`) within your script will not format `SyntaxError` exceptions, as these occur before script execution. Only runtime exceptions will be prettified this way.
fix
For universal formatting, including `SyntaxError`s, activate `pretty-errors` at Python startup by running `python -m pretty_errors` in your terminal once. This sets up your Python environment to include `pretty-errors` automatically.
affects: All versions
gotchaPrettyErrors hooks into Python's exception handling system. This can potentially interfere with other libraries that also modify stack traces or exception reporting, leading to unexpected behavior or conflicts.
fix
If conflicts arise, consider conditionally activating `pretty_errors` using `pretty_errors.activate()` within your code, or set the `PYTHON_PRETTY_ERRORS_ISATTY_ONLY` environment variable to '1' to only activate `pretty_errors` in interactive terminal sessions.
affects: All versions
Errors
Common errors & fixes
PrettyErrors traceback appears, but without any colors, or output is garbled.
The terminal emulator does not support ANSI color codes, or `pretty-errors` is configured for color output in a monochrome environment.
fix
Ensure you are using a color-capable terminal (e.g., PowerShell, Cmder, VS Code terminal). If running in a monochrome environment, call `pretty_errors.mono()` after importing `pretty_errors` or configure colors manually to be empty strings.
SyntaxError: invalid syntax (or similar syntax error) is not formatted by pretty-errors.
The `pretty-errors` library was imported manually within the script, or was not activated universally at Python startup.
fix
Activate `pretty-errors` universally by running `python -m pretty_errors` in your terminal once. This configures Python's startup procedure to include `pretty-errors`, allowing it to handle `SyntaxError` exceptions before your script even runs.
PrettyErrors is not active when running my script, or standard Python tracebacks are shown.
The `pretty_errors` module was not imported or activated, or it was imported too late in the script after another library took over exception handling.
fix
Ensure `import pretty_errors` is one of the *very first* imports in your main script. Alternatively, for universal activation across all Python invocations, run `python -m pretty_errors` once to configure your Python environment.
Upgrade
Version history
1.2.25latest on PyPI · released Nov 24, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
12
Resources
pretty-errors — pip install pretty-errors · libregistry