Syntax-highlighting, declarative and composable pretty printer for Python 3.6+
Project description
PrettyPrinter
Syntax-highlighting, declarative and composable pretty printer for Python 3.6+
pip install prettyprinter
Drop in replacement for the standard library pprint: just rename pprint to prettyprinter in your imports.
Uses a modified Wadler-Leijen layout algorithm for optimal formatting
Write pretty printers for your own types with a dead simple, declarative interface
Pretty print common Python values:
>>> from datetime import datetime
>>> from prettyprinter import pprint
>>> pprint({'beautiful output': datetime.now()})
{
'beautiful output': datetime.datetime(
year=2017,
month=12,
day=12,
hour=0,
minute=43,
second=4,
microsecond=752094
)
}
As well as your own, without any manual string formatting:
>>> class MyClass:
... def __init__(self, one, two):
... self.one = one
... self.two = two
>>> from prettyprinter import register_pretty, pretty_call
>>> @register_pretty(MyClass)
... def pretty_myclass(value, ctx):
... return pretty_call(ctx, MyClass, one=value.one, two=value.two)
>>> pprint(MyClass((1, 2, 3), {'a': 1, 'b': 2}))
MyClass(one=(1, 2, 3), two={'a': 1, 'b': 2})
>>> pprint({'beautiful output': datetime.now(), 'beautiful MyClass instance': MyClass((1, 2, 3), {'a': 1, 'b': 2})})
{
'beautiful MyClass instance': MyClass(
one=(1, 2, 3),
two={'a': 1, 'b': 2}
),
'beautiful output': datetime.datetime(
year=2017,
month=12,
day=12,
hour=0,
minute=44,
second=18,
microsecond=384219
)
}
Comes packaged with the following pretty printer definitions:
datetime - (installed by default)
enum - (installed by default)
pytz - (installed by default)
attrs - any new class you create will be pretty printed automatically
django - your Models and QuerySets will be pretty printed automatically
requests - automatically pretty prints Requests, Responses, Sessions, and more from the requests library
Free software: MIT license
Documentation: Documentation.
History
0.6.0 (2017-12-21)
No backwards incompatible changes.
Added pretty printer definitions for the requests library. To use it, include 'requests' in your install_extras call: prettyprinter.install_extras(include=['requests']).
0.5.0 (2017-12-21)
No backwards incompatible changes.
Added integration for the default Python shell
Wrote docs to explain integration with the default Python shell
Check install_extras arguments for unknown extras
0.4.0 (2017-12-14)
Revised comment to accept both normal Python values and Docs, and reversed the argument order to be more Pythonic
0.3.0 (2017-12-12)
Add set_default_style function, improve docs on working with a light background
0.2.0 (2017-12-12)
Numerous API changes and improvements.
0.1.0 (2017-12-07)
First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for prettyprinter-0.6.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 740fb1679d97102dbbd6713f8c8a3195cc7a9db2a5d34c1b91af5be2c85abbed |
|
MD5 | c66181f24fecb89812a88e97e9d1ba75 |
|
BLAKE2b-256 | 442250e11ad880a64c62c1ce0321ec2d271ec033af577d0cbf30dec63be6d6f0 |