Pretty print but it's prettier than pretty print
Project description
beautifulprint
Pretty print, but it's prettier than pretty print (because it's colorized!)
Run pip install printbeautifully
Beautifulprint is a light-weight python package that allows you to easily and simply print data in a nice format. It also has strong customisation using function decorators and theme objects.
Note: it does not yet support self-referencing dictionaries/tuples
Helpful links
Usage
- Print a builtin data structure:
from beautifulprint import bprint
bprint({
"key": "value",
"number_list": [1, 2, 3],
"it also supports tuples!": (True, None, False)
})
- Print multiple pieces of data:
from beautifulprint import bprint
bprint({
"key": "value",
"number_list": [1, 2, 3],
"it also supports tuples!": (True, None, False)
}, # Just use a comma!
["a", "b", "c", 123.456]
)
- Use a different theme:
from beautifulprint import bprint, themes
with themes.BLAND: # You use a with statement
bprint({
"key": "value",
"number_list": [1, 2, 3],
"it also supports tuples!": (True, None, False)
})
- Or make your own theme:
from beautifulprint import bprint, Theme, pepr, rgb, RESET
my_theme = Theme("my cool theme") # Name of theme. Just used for printing the theme object
@my_theme.packer(cls=dict) # This decorator registers this function to my_theme as a way to format/pack a dictionary
def pack_dict(value: dict) -> str:
# This method will only be passed a dict (because of the decorator above) and must return a string
ret = 'dict('
for key, value in value.items():
# You use pepr, which will handle formatting child objects.
# You handle coloring in here as well, with the rgb function. You can also you colorama if you want
ret += f"{rgb(255, 0, 255)}{pepr(key)}{RESET} = {rgb(0, 255, 0)}{pepr(value, strip=True)}{RESET}, "
# The value item shouldn't be placed on a newline, so we strip the whitespace
ret += '\n)'
return ret
with my_theme: # You use a with statement
bprint({
"key": "value",
"number_list": [1, 2, 3],
"it also supports tuples!": (True, None, False)
})
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 printbeautifully-0.2.0.tar.gz.
File metadata
- Download URL: printbeautifully-0.2.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62e044e95b964c5d784b52465feebdbfe41b64d50bc6925c403c2600f6e16195
|
|
| MD5 |
fb9906f4666f6a4b92566148268b9e45
|
|
| BLAKE2b-256 |
10d2ebfc79077a28a240a9bc122f8b1ccd19305a823d70b29f47053af384f53f
|
File details
Details for the file printbeautifully-0.2.0-py3-none-any.whl.
File metadata
- Download URL: printbeautifully-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c86bc81b36b0cc401c922b866e330a88761b4781a8d34346ab61a38bf3f57b7
|
|
| MD5 |
9869b59c157b1a5be5021d37215fa36d
|
|
| BLAKE2b-256 |
64ae8890e03d5581a7da4d780bfb7df371e6ed66922d2d62018b7d4a35eba354
|