Skip to main content

Python pretty formatting package

Project description

PyPformat

tests examples ruff - linter & formatter coverage


Overview

PyPformat is a simple and highly customizable python pretty-formatting package designed as an alternative to the built-in pprint library - PyPformat uses a different, more natural formatting style and provides extensive personalization capabilities, including text colorizing or customized indentation marking, on top of the basic options like compact printing.


The example below demostrates the difference in the default outputs produced by the pprint and PyPformat libraries.

>>> from pprint import pprint
>>> import pformat as pf
>>>
>>> from collections import ChainMap, Counter, OrderedDict, UserDict, defaultdict
>>>
>>> mapping = {
...     "key1": 1,
...     "key2": OrderedDict({"key3": 3, "key4": 4}),
...     "key5": defaultdict(
...         str,
...         {
...             "key6": 6,
...             "a_very_long_dictionary_key7": ChainMap(
...                 {"key10": [10, 11, 12, 13], "key8": 8, "key9": 9}
...             ),
...             "key11": Counter("Hello"),
...         },
...     ),
...     "key12": UserDict({0: "a", 1: "b", 2: "c"}),
... }
>>>
>>> pprint(mapping)
{'key1': 1,
 'key12': {0: 'a', 1: 'b', 2: 'c'},
 'key2': OrderedDict({'key3': 3, 'key4': 4}),
 'key5': defaultdict(<class 'str'>,
                     {'a_very_long_dictionary_key7': ChainMap({'key10': [10,
                                                                         11,
                                                                         12,
                                                                         13],
                                                               'key8': 8,
                                                               'key9': 9}),
                      'key11': Counter({'l': 2, 'H': 1, 'e': 1, 'o': 1}),
                      'key6': 6})}
>>>
>>> formatter = pf.PrettyFormatter()
>>> print(formatter(mapping))
{
    'key1': 1,
    'key2': OrderedDict({
        'key3': 3,
        'key4': 4,
    }),
    'key5': defaultdict(<class 'str'>, {
        'key6': 6,
        'a_very_long_dictionary_key7': ChainMap({
            'key10': [
                10,
                11,
                12,
                13,
            ],
            'key8': 8,
            'key9': 9,
        }),
        'key11': Counter({
            'H': 1,
            'e': 1,
            'l': 2,
            'o': 1,
        }),
    }),
    'key12': {
        0: 'a',
        1: 'b',
        2: 'c',
    },
}

[!IMPORTANT]

  • The minimum (tested) python version required to use the PyPformat package is 3.9.
  • The complete functionality of the PyPformat package (including all format configuration options) is described in PyPformat - Usage and PyPformat - Utility documents.
  • While the PyPformat package is already quite versatile and customizable, its development is ongoing. A detailed list of the planned features/improvements can be found in the PyPformat - TODO document (please note that this list is not fixed and may be expanded).


Installation

The PyPformat package can be installed via pip:

pip install pypformat


For Developers

The PyPformat - Dev notes document contains the information about project development, testing and formatting.



Licence

The PyPformat project is licenced under the MIT Licence, which can be inspected in the LICENCE file in the project's root directory.

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

pypformat-1.2.4.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

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

pypformat-1.2.4-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file pypformat-1.2.4.tar.gz.

File metadata

  • Download URL: pypformat-1.2.4.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for pypformat-1.2.4.tar.gz
Algorithm Hash digest
SHA256 80226d4accb55e94504d6619536513f02c5dbcda4e89b264e013fa0d507a3a92
MD5 7cff3ce34ca2480392f6221f2fa79b1a
BLAKE2b-256 d3eb1d61305968294b6609dc21087b645b818a1ba99e5821c50c26b251f02037

See more details on using hashes here.

File details

Details for the file pypformat-1.2.4-py3-none-any.whl.

File metadata

  • Download URL: pypformat-1.2.4-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for pypformat-1.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3d72f0f5de7b82d2ed4eff06f6d8e686e64685074f967c1d0be0439d6b3444e9
MD5 7e16e7f745b1bdf2a2290577316c39ef
BLAKE2b-256 4a2d9477b659856fac07370a44e2e267602cbcc4a412265b198a89a914e5134e

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