A lightweight pretty-printer for data structures.
Project description
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
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 beautipy-0.1.1.tar.gz.
File metadata
- Download URL: beautipy-0.1.1.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5aa7a8f072896498120894defeb563cf31be0ab4a96573ea5e1b1522171e21fa
|
|
| MD5 |
383d632cc450397e4b8c1e308d2c0c3a
|
|
| BLAKE2b-256 |
c52390dbf86887802368eb31ec9601fc7a4593693407c23db6510bf1e7eddc4b
|
File details
Details for the file beautipy-0.1.1-py3-none-any.whl.
File metadata
- Download URL: beautipy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf2c62e645c62d41ae8442d5c136e6566dd213dc558342f99db040a5b95b7553
|
|
| MD5 |
7fbac6ae0bffc05bb557a3cd8c79425e
|
|
| BLAKE2b-256 |
73fe3d08c850660a5b4e4ff38e76f4a0f096416695fa9d5cf510c5045ee1444e
|