BeautiPy
A lightweight pretty-printer for complex, nested data structures and structured text. Improves readability by adding indentation and line breaks.
Features
- Works with any object via its
str()representation - Handles non-standard structured text
- Configurable indentation and formatting rules
- Simple and dependency-free
- Includes a CLI tool
Installation
pip install beautipy
Or using uv:
uv add beautipy
Requires Python 3.8 or higher.
Quick Start
Python
from beautipy import beautify
data = {'method': 'GET', 'status': 200}
print(beautify(data))
Output:
{
'method': 'GET',
'status': 200
}
Terminal
cat data.txt | beautipy > formatted.txt
You can also run as a module: python -m beautipy.
Usage
Python API
The core functionality is provided by the beautify function.
from beautipy import beautify
beautify(
obj: object,
*,
blank_line_depth: int = 0,
opener_same_line: bool = False,
compact_operators: bool = False,
expand_empty: bool = False,
indent: str = ' '
) -> str
| Parameter | Type | Default | Description |
|---|---|---|---|
obj |
object |
- | Object to format. If not a string, str(obj) is used. |
blank_line_depth |
int |
0 |
Number of initial nesting levels that get a blank line. |
opener_same_line |
bool |
False |
Keep {, [, ( on the same line. |
compact_operators |
bool |
False |
Omit spaces around = and :. |
expand_empty |
bool |
False |
Expand empty structures (e.g. {}) to multiple lines. |
indent |
str |
' ' |
Indentation string (4 spaces by default). |
Raises: ValueError if blank_line_depth < 0.
Command Line
BeautiPy can also be used directly from the terminal.
# From file
beautipy < messy.json
# From stdin
echo '[1,2,3]' | beautipy
# From argument
beautipy '{"key":"value"}'
# Multiple options
beautipy --indent ' ' -b 2 -s '{k1:[v11,v12], k2:[v21,v22]}'
Options
-b,--blank-line-depth N: Add blank lines at depth N. Default is0.-s,--opener-same-line: Keep opening brackets inline.-o,--compact-operators: Do not add spaces around=and:.-e,--expand-empty: Expand empty structures (e.g.[]).-i,--indent STR: Set indentation string. Default is' '(4 spaces).--version: Show version information.
Non-standard Structured Text
Since BeautiPy operates on text rather than parsing, it can format custom structured text and does not require valid JSON, Python, or any specific syntax:
text = 'Arya[age:9,parents:("mother"="Tara",father:Bardia),children:{}]'
print(beautify(text))
Output:
Arya
[
age: 9,
parents:
(
"mother" = "Tara",
father: Bardia
),
children: {}
]
More usage examples can be found in the examples/ directory:
How It Works
BeautiPy operates purely at the character level:
- Reads input as text
- Identifies structural characters:
{,[,(,,, etc. - Applies formatting rules (indentation, spacing, newlines)
This allows reasonable output for custom or made-up syntax.
Notes
- Not a parser: Cannot extract or modify data — no semantic understanding
- Not a validator: Does not check syntactic correctness
Contributing
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch (
git switch -c feature/amazing-featureorgit checkout -b feature/amazing-feature) - Install the package in development mode with dev dependencies:
pip install -e ".[dev]"oruv sync --extra dev
- Run tests:
pytest(from the project root) - Submit a pull request
Please ensure:
- Code follows PEP 8
- Changes are well-documented
License
MIT License — free to use, modify, and distribute. See the LICENSE file for details.
Links
Metadata
Release files for beautipy 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| beautipy-0.1.1.tar.gz | 14.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| beautipy-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.4 kB
Release files / beautipy-0.1.1.tar.gz
| Download URL | beautipy-0.1.1.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5aa7a8f072896498120894defeb563cf31be0ab4a96573ea5e1b1522171e21fa
|
|
BLAKE2b-256 checksum How to use checksums |
c52390dbf86887802368eb31ec9601fc7a4593693407c23db6510bf1e7eddc4b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.10
|
Release files / beautipy-0.1.1-py3-none-any.whl
| Download URL | beautipy-0.1.1-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cf2c62e645c62d41ae8442d5c136e6566dd213dc558342f99db040a5b95b7553
|
|
BLAKE2b-256 checksum How to use checksums |
73fe3d08c850660a5b4e4ff38e76f4a0f096416695fa9d5cf510c5045ee1444e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.10
|