{"id":27634882,"url":"https://github.com/patrick-kidger/wadler_lindig","last_synced_at":"2025-11-17T15:32:43.331Z","repository":{"id":271078341,"uuid":"911350582","full_name":"patrick-kidger/wadler_lindig","owner":"patrick-kidger","description":"A Wadler--Lindig pretty printer for Python","archived":false,"fork":false,"pushed_at":"2025-04-13T16:10:40.000Z","size":103,"stargazers_count":37,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-20T04:15:33.987Z","etag":null,"topics":["lindig","pprint","pretty-printer","wadler"],"latest_commit_sha":null,"homepage":"https://docs.kidger.site/wadler_lindig/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patrick-kidger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["patrick-kidger"]}},"created_at":"2025-01-02T20:10:25.000Z","updated_at":"2025-04-13T16:52:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"db83d59a-a087-495c-8fe0-1fbef4553a54","html_url":"https://github.com/patrick-kidger/wadler_lindig","commit_stats":null,"previous_names":["patrick-kidger/wadler_lindig"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrick-kidger%2Fwadler_lindig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrick-kidger%2Fwadler_lindig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrick-kidger%2Fwadler_lindig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrick-kidger%2Fwadler_lindig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrick-kidger","download_url":"https://codeload.github.com/patrick-kidger/wadler_lindig/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250500872,"owners_count":21440902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lindig","pprint","pretty-printer","wadler"],"created_at":"2025-04-23T19:38:52.793Z","updated_at":"2025-11-17T15:32:38.296Z","avatar_url":"https://github.com/patrick-kidger.png","language":"Python","funding_links":["https://github.com/sponsors/patrick-kidger"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eA Wadler–Lindig ✨pretty-printer✨ for Python\u003c/h1\u003e\n\nThis library is for you if you need:\n\n- Something like the built-in `pprint.pprint`, but which consumes less horizontal space. For example in error messages.\n- If you have complicated custom types that you'd like to create pretty well-formatted reprs for. For example nested trees of dataclasses / PyTorch modules / etc.\n\nMain features:\n\n- Absolutely tiny implementation (77 lines of code for the main Wadler–Lindig algorithm, 223 more for teaching it how to handle all Python types).\n- Simpler than the original algorithm by Wadler \u0026 Lindig (removes some dead code).\n- Supports multi-line unbroken text strings.\n- Supports ANSI escape codes and colours.\n- Zero dependencies.\n\n## Installation\n\n```bash\npip install wadler_lindig\n```\n\n## Documentation\n\nAvailable at [https://docs.kidger.site/wadler_lindig](https://docs.kidger.site/wadler_lindig).\n\n## Example\n\n```python\nimport dataclasses\nimport numpy as np\nimport wadler_lindig as wl\n\n@dataclasses.dataclass\nclass MyDataclass:\n    x: list[str]\n    y: np.ndarray\n\nobj = MyDataclass([\"lorem\", \"ipsum\", \"dolor sit amet\"], np.zeros((2, 3)))\n\nwl.pprint(obj, width=30, indent=4)\n# MyDataclass(\n#     x=[\n#         'lorem',\n#         'ipsum',\n#         'dolor sit amet'\n#     ],\n#     y=f64[2,3](numpy)\n# )\n```\n\n## API at a glance\n\nFor day-to-day pretty-printing objects: `pprint` (to stdout), `pformat` (as a string), `pdiff` (between two objects).\n\nFor creating custom pretty-printed representations:\n\n- The core Wadler–Lindig document types: `AbstractDoc`, `BreakDoc`, `ConcatDoc`, `GroupDoc`, `NestDoc`, `TextDoc`.\n- `pdoc` will convert any Python object to a Wadler–Lindig document, with the `__pdoc__` method called on custom types if it is available.\n- `ansi_format` (to add ANSI colour codes), `ansi_strip` (to remove ANSI codes).\n- Several common helpers for creating Wadler–Lindig documents: `array_summary`, `bracketed`, `comma`, `join`, `named_objs`.\n\n## FAQ\n\n\u003cdetails\u003e\n\u003csummary\u003eWhat is the difference to the built-in `pprint` library?\u003c/summary\u003e\n\n1. The main difference is that the Wadler–Lindig algorithm produces output like\n\n```\nMyDataclass(\n  x=SomeNestedClass(\n    y=[1, 2, 3]\n  )\n)\n```\n\nIn contrast `pprint` produces output like\n\n```\nMyDataclass(x=SomeNestedClass(y=[1,\n                                 2,\n                                 3]))\n```\n\nwhich consumes a lot more horizontal space.\n\n2. By default we print NumPy arrays / PyTorch tensors / etc. in a concise form e.g. `f32[2,3](numpy)` to denote a NumPy array with shape `(2, 3)` and dtype `float32`. (Set `short_arrays=False` to disable this.)\n\n3. We provide support for customising the pretty-printed representations of your custom types. Typically this is done via:\n\n    ```python\n    import wadler_lindig as wl\n\n    class MyAmazingClass:\n        def __pdoc__(self, **kwargs) -\u003e wl.AbstractDoc:\n            ...  # Create your pretty representation here!\n\n        def __repr__(self):\n            # Calls `__pdoc__` and then formats to a particular width.\n            return wl.pformat(self, width=80)\n    ```\n\n    In addition we support a `wadler_lindig.pprint(..., custom=...)` argument, if you don't own the type and so cannot add a `__pdoc__` method.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eWhat is the difference to `black` or `rust format`?\u003c/summary\u003e\n\nThe above are formatters for your source code. This `wadler_lindig` library is intended as an alternative to the built-in `pprint` library, which pretty-format Python objects at runtime.\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrick-kidger%2Fwadler_lindig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrick-kidger%2Fwadler_lindig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrick-kidger%2Fwadler_lindig/lists"}