Skip to main content

Syntax-highlighting, declarative and composable pretty printer for Python 3.6+

Project description

PrettyPrinter

Documentation

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)

  • dataclasses - any new class you create will be pretty printed automatically

  • 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

History

0.7.0 (2017-12-23)

Breaking change: instances of lists, sets, frozensets, tuples and dicts will be truncated to 1000 elements by default when printing.

  • Added pretty printing definitions for dataclasses

  • Improved performance of splitting strings to multiple lines by ~15%

  • Added a maximum sequence length that applies to subclasses of lists, sets, frozensets, tuples and dicts. The default is 1000. There is a trailing comment that indicates the number of truncated elements. To remove truncation, you can set max_seq_len to None using set_default_config explained below.

  • Added ability to change the default global configuration using set_default_config. The functions accepts zero to many keyword arguments and replaces those values in the global configuration with the ones provided.

from prettyprinter import set_default_config

set_default_config(
    style='dark',
    max_seq_len=1000,
    width=79,
    ribbon_width=71,
    depth=None,
)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prettyprinter-0.7.0.tar.gz (343.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prettyprinter-0.7.0-py2.py3-none-any.whl (35.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file prettyprinter-0.7.0.tar.gz.

File metadata

  • Download URL: prettyprinter-0.7.0.tar.gz
  • Upload date:
  • Size: 343.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for prettyprinter-0.7.0.tar.gz
Algorithm Hash digest
SHA256 c18dd25204413bc79518361717e1e45164b84b01f6e5bf1fcbb3e2cb8b264879
MD5 6c595d8202f2c2553be26b78cd0e4fd9
BLAKE2b-256 c80a618086ed4f0c65bba65ed27c4e82dfbdb7090421941c24ec26ebc06786a8

See more details on using hashes here.

File details

Details for the file prettyprinter-0.7.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for prettyprinter-0.7.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1e41a70e37c9c01a2866542e4e876abdac1ef2316a0720faccb316041899ff27
MD5 53d78e45f45c2cf966a88e4dd54e6c06
BLAKE2b-256 6a7bcebcc0cbb51c3b4e1cf88d27ece08421438092d77327a12cef2bb71f9210

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page