Python pretty formatting package
Project description
PyPformat
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
PyPformatpackage is 3.9.- The complete functionality of the
PyPformatpackage (including all format configuration options) is described in PyPformat - Usage and PyPformat - Utility documents.- While the
PyPformatpackage 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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pypformat-1.2.2.tar.gz.
File metadata
- Download URL: pypformat-1.2.2.tar.gz
- Upload date:
- Size: 19.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f246a0e3776d88d2aefdff456e01ebdc28e6d52a28e8b7079dc9e2a1302351e
|
|
| MD5 |
9e810400bb51c87342c3b2746a56fafe
|
|
| BLAKE2b-256 |
9c53cefab0817fb9aa6f359fb89d16d87a7c055312e905c9a806190e251be2ed
|
File details
Details for the file pypformat-1.2.2-py3-none-any.whl.
File metadata
- Download URL: pypformat-1.2.2-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a28602e23f80ced6bbad2388fcacb70fe119aa90df98ff219df0dc786bfcb0dc
|
|
| MD5 |
3018a38e99588d2a019c64c35983ffa0
|
|
| BLAKE2b-256 |
16ed757343bc09d8d3050efcdcfb28a9037acfe1ca12651ffb9fbbb20ecc9299
|