Format Python objects as repr-like plain text or width-aware Rich renderables.
Project description
✨ Features
- Plain-text formatting for logs and snapshots, plus a Rich renderable path for width-aware console output.
- Built-in handling for common containers,
fieldz-compatible models, and objects with__rich_repr__. - Lazy summaries for NumPy, JAX, Torch, and Warp arrays when those libraries are already imported.
- Shared-reference and cycle tracking for referencable objects such as mappings, sets, frozensets, and custom containers.
- A small customization surface through
__pretty__(),register_type(),register_func(), andregister_lazy(). - Environment-backed defaults through
PRETTY_*, with per-call overrides for logs, snapshots, tests, and interactive debugging.
📦 Installation
uv add liblaf-pretty
# or
pip install liblaf-pretty
🧪 Quick Start
Use pformat() when you want stable plain text:
from liblaf.pretty import pformat
print(pformat({"alpha": [1, 2, 3]}), end="")
{'alpha': [1, 2, 3]}
Use plower() when you want a Rich renderable whose layout is chosen later by
the target Console. If you already have a console, use pprint() or its alias
pp() for the print-now path.
🎛️ Configuration
The public formatting helpers accept per-call overrides for:
max_level,max_list,max_array,max_dictmax_string,max_long,max_otherindenthide_defaults
Those values can also come from environment variables:
export PRETTY_MAX_LIST=2
export PRETTY_INDENT='[bold]>>[/] '
indent accepts plain text, Rich markup, ANSI-colored strings, or
rich.text.Text.
🔢 Arrays
Array libraries are optional. Once NumPy, JAX, Torch, or Warp is already loaded,
liblaf.pretty formats small arrays as compact dtype-and-shape summaries:
import numpy as np
from liblaf.pretty import pformat
print(pformat(np.zeros((2, 3), dtype=np.float32)), end="")
f32[2,3](numpy)
If any dimension is larger than max_array, the formatter falls back to the
object's normal repr instead of importing or traversing large values.
🔁 Shared References
Repeated referencable objects are annotated on first appearance and then render
as <Type @ hexid> references later in the output. Lists and tuples stay safe
too, but they repeat their value instead of collapsing into a reference tag.
🧩 Custom Formatting
Reach for the smallest hook that matches the job:
- Implement
__pretty__(self, ctx)when you own the class. - Use
register_type()for a concrete type and its subclasses. - Use
register_func()for structural matching. - Use
register_lazy()for optional dependencies that should only activate after their module is already imported.
PrettyContext gives custom formatters the builder helpers they usually need:
ctx.container(), ctx.leaf(), ctx.positional(), ctx.name_value(), and
ctx.key_value().
For the full walkthrough, see the custom formatter guide.
🛠️ Development
Common workflows:
mise run lint
mise run docs:build
mise run docs:serve
mise run gen:ref-pages
nox
nox runs the test matrix across Python 3.12, 3.13, and 3.14, with both
highest and lowest-direct dependency resolution.
📝 License
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 liblaf_pretty-0.2.0.tar.gz.
File metadata
- Download URL: liblaf_pretty-0.2.0.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
335fe1985a488fe7903bdf2a3dcec8996037b340db17db87b36f94a1921979ef
|
|
| MD5 |
28333fe62dabd3fe3e3618662495bd57
|
|
| BLAKE2b-256 |
3b0d98f54b92677bfff585574d32d1ff7777cd21df77fd3fd63b2a39a7f41a7c
|
Provenance
The following attestation bundles were made for liblaf_pretty-0.2.0.tar.gz:
Publisher:
python-release.yaml on liblaf/pretty
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
liblaf_pretty-0.2.0.tar.gz -
Subject digest:
335fe1985a488fe7903bdf2a3dcec8996037b340db17db87b36f94a1921979ef - Sigstore transparency entry: 1439858415
- Sigstore integration time:
-
Permalink:
liblaf/pretty@9da3cd07f23eecb3ba55a9b65e5fe4cbc5c6eda5 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/liblaf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yaml@9da3cd07f23eecb3ba55a9b65e5fe4cbc5c6eda5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file liblaf_pretty-0.2.0-py3-none-any.whl.
File metadata
- Download URL: liblaf_pretty-0.2.0-py3-none-any.whl
- Upload date:
- Size: 45.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ace1f75120c52babe4ba82a63aa0c71340b94aa651892e949b5152e2a8d0e8d2
|
|
| MD5 |
0c595805a2f5bc4040fd3b96fa5985b8
|
|
| BLAKE2b-256 |
22fc463736ab283f35a8844fe4d342d25229b276b771db0f78899d2fc59e0274
|
Provenance
The following attestation bundles were made for liblaf_pretty-0.2.0-py3-none-any.whl:
Publisher:
python-release.yaml on liblaf/pretty
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
liblaf_pretty-0.2.0-py3-none-any.whl -
Subject digest:
ace1f75120c52babe4ba82a63aa0c71340b94aa651892e949b5152e2a8d0e8d2 - Sigstore transparency entry: 1439858420
- Sigstore integration time:
-
Permalink:
liblaf/pretty@9da3cd07f23eecb3ba55a9b65e5fe4cbc5c6eda5 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/liblaf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yaml@9da3cd07f23eecb3ba55a9b65e5fe4cbc5c6eda5 -
Trigger Event:
release
-
Statement type: