PrettyPrinter is a Python library (version 0.18.0) that offers syntax-highlighting, declarative, and composable pretty printing for Python 3.5+ data structures. It aims to be a feature-rich alternative to Python's standard `pprint` module, providing improved readability, customizability, and integrations with other libraries. Its release cadence has been somewhat irregular, but the 0.18.0 version released in 2019 has been stable, suggesting a mature library.
pip install prettyprinterVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic pretty-printing of a nested dictionary and how to define custom pretty-printing rules for your own classes using `@register_pretty`. It also notes how to enable shell integrations for a more persistent pretty-printing experience.
If sorted dictionary keys are required, explicitly pass `sort_dict_keys=True` to `pprint()` or `pformat()`, or set this option in your custom `PrettyContext`.
Always explicitly `from prettyprinter import pprint` to ensure you are using the external library. Avoid `import pprint` if you intend to use `prettyprinter`'s features, as it will import the standard library module.
Call `from prettyprinter import install_extras; install_extras(['python'])` for the default shell or `install_extras(['ipython'])` for IPython. You can also specify other libraries like `install_extras(include=['dataclasses', 'requests'])`. For persistent shell integration, consider setting the `PYTHONSTARTUP` environment variable.
Update your custom pretty printer definitions to use `ctx.assoc(...)` instead of `ctx.set(...)` for context manipulation.
For optimal and consistent pretty-printing of custom types, use `prettyprinter.register_pretty` with a dedicated pretty printer function, combined with `pretty_call`, rather than solely relying on `__repr__`.
Install the package using pip: `pip install prettyprinter`
Import the 'pprint' function: `from prettyprinter import pprint` or use `import prettyprinter` and then `prettyprinter.pprint(...)`
Ensure you are importing `install_extras` from the `prettyprinter` library: `from prettyprinter import install_extras`
Ensure you are importing `register_pretty` from the `prettyprinter` library: `from prettyprinter import register_pretty`
No dependency data recorded yet.