Registry / serialization / wadler-lindig

wadler-lindig

JSON →
library0.1.7pypypi✓ verified 26d ago

Wadler-Lindig is a Python library that provides a pretty-printer based on the Wadler–Lindig algorithm. It serves as an alternative to the built-in `pprint.pprint`, aiming to produce output that consumes less horizontal space, which is particularly useful for complex custom types, error messages, or nested data structures. The library is characterized by its compact implementation, support for multi-line strings and ANSI escape codes, and zero runtime dependencies. The current version is 0.1.7, and it appears to be actively maintained.

pip install wadler-lindig
INSTALL
IMPORT
SIG · WADLER-LINDIG
W
wadler-lindig
serializationpythonv0.1.7
Install
1.5s avg
Import
171ms
Disk
15MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 1.5s
py 3.11
✓ —
✓ 1.6s
py 3.12
✓ —
✓ 1.4s
py 3.13
✓ —
✓ 1.5s
py 3.9
✕ build_error
✕ build_error
15MB installed
● package 15MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pprint
from wadler_lindig import pprint
import wadler_lindig as wl
pformat
from wadler_lindig import pformat
pdiff
from wadler_lindig import pdiff

This quickstart demonstrates basic usage of `wadler_lindig.pprint` and `pformat` with a dataclass containing a list and a NumPy array. It also illustrates how to customize the pretty-printing for a custom class using the `__pdoc__` method. Note that `numpy` is used for demonstration purposes, but is not a core dependency of the `wadler-lindig` library itself.

import dataclasses import numpy as np import wadler_lindig as wl @dataclasses.dataclass class MyDataclass: x: list[str] y: np.ndarray obj = MyDataclass( x=["lorem", "ipsum", "dolor sit amet", "consectetur", "adipiscing elit"], y=np.zeros((2, 3)) ) print("\n--- Default pprint output ---") print(obj) print("\n--- wadler_lindig.pprint output (width=30, indent=4) ---") wl.pprint(obj, width=30, indent=4) print("\n--- wadler_lindig.pformat output (width=20) ---") formatted_str = wl.pformat(obj, width=20, indent=2) print(formatted_str) # Example of custom pretty-printing for a non-dataclass type class MyCustomClass: def __init__(self, value): self.value = value def __pdoc__(self, **kwargs) -> wl.AbstractDoc: return wl.TextDoc(f"<MyCustomClass: {self.value}> ") def __repr__(self): return wl.pformat(self, width=80) custom_obj = MyCustomClass(123) print("\n--- Custom object with __pdoc__ ---") wl.pprint(custom_obj)
Debug
Known issues
gotchaThe `width` argument in `pprint` and `pformat` is a 'best-effort' maximum. It may be exceeded if there are unbroken pieces of text (e.g., long strings) that are inherently wider than the specified width.
fix
Design custom `__pdoc__` methods or preprocess long strings if strict width adherence is critical for specific parts of the output.
affects: All
gotchaCustomizing pretty-printing for your own types typically uses the `__pdoc__` method, which is specific to this library. For third-party types you don't own, use the `custom` argument in `wl.pprint` or `wl.pformat` instead of `__pdoc__`.
fix
For your types, implement `def __pdoc__(self, **kwargs) -> wl.AbstractDoc: ...`. For external types, pass `custom=your_custom_function` to the pretty-printing calls.
affects: All
gotchaThis library is designed for pretty-formatting Python *objects* at runtime, similar to the built-in `pprint` module. It is *not* a source code formatter like Black or Rustfmt, and should not be used for reformatting Python source files.
fix
Understand its purpose as an object introspection and display tool. For source code formatting, use dedicated tools like Black or Ruff.
affects: All
gotchaOutput format differs from Python's built-in `pprint.pprint`. `wadler-lindig` prioritizes reducing horizontal space and often indents more aggressively. It also provides a concise summary for NumPy arrays by default (e.g., `f64[2,3](numpy)`).
fix
If expecting exact `pprint` behavior, be aware of these differences. For NumPy array verbosity, set `short_arrays=False` in `pprint`/`pformat` calls. Adapt custom pretty-printing logic if migrating from `pprint`.
affects: All
Upgrade
Version history
0.1.7latest on PyPI · released Jun 18, 2025
Audit
Dependencies
numpyoptionalUsed in quickstart example to demonstrate concise array formatting.
Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
1
Resources
wadler-lindig — pip install wadler-lindig · libregistry