reprobate 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Adam Ashenfelter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,151 @@
1
+ Metadata-Version: 2.4
2
+ Name: reprobate
3
+ Version: 0.1.0
4
+ Summary: Budget-controlled repr for Python objects.
5
+ Author: ashenfad
6
+ License-Expression: MIT
7
+ Keywords: repr,pretty-print,budget,truncation,llm
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Provides-Extra: dev
21
+ Requires-Dist: ruff; extra == "dev"
22
+ Requires-Dist: pre-commit; extra == "dev"
23
+ Requires-Dist: pytest; extra == "dev"
24
+ Requires-Dist: pytest-timeout; extra == "dev"
25
+ Provides-Extra: test
26
+ Requires-Dist: pytest; extra == "test"
27
+ Requires-Dist: pytest-timeout; extra == "test"
28
+ Requires-Dist: numpy; extra == "test"
29
+ Requires-Dist: pandas; extra == "test"
30
+ Requires-Dist: Pillow; extra == "test"
31
+ Requires-Dist: polars; extra == "test"
32
+ Requires-Dist: pyarrow; extra == "test"
33
+ Requires-Dist: pydantic; extra == "test"
34
+ Dynamic: license-file
35
+
36
+ # reprobate 🖨️
37
+
38
+ Budget-controlled repr for Python objects.
39
+
40
+ Renders any Python object into a string that fits within a character budget. Nested structures degrade gracefully: full values, then type stubs, then counts. Zero dependencies. Pluggable via a type registry and a `__budget_repr__` protocol.
41
+
42
+ ## Features
43
+
44
+ - **Hard budget guarantee** -- output is always `<= budget` characters
45
+ - **Three-phase degradation** -- full render, then `name=<type(len)>` stubs, then `...N more` counts
46
+ - **Greedy and even policies** -- prioritize depth (first fields in detail) or breadth (all fields equally)
47
+ - **Cycle detection** -- circular references render as `<...>` instead of stack overflows
48
+ - **Type registry** -- `@register(MyType)` for custom budget-aware renderers
49
+ - **Protocol method** -- `__budget_repr__(self, budget)` on any class
50
+ - **Optional extensions** -- arrow, numpy, pandas, pil, polars, pydantic renderers (guarded imports, zero cost if absent)
51
+
52
+ ## Install
53
+
54
+ ```bash
55
+ pip install reprobate
56
+ ```
57
+
58
+ Zero dependencies. Optional renderers activate automatically when their libraries are already installed (numpy, pandas, polars, pyarrow, Pillow, pydantic).
59
+
60
+ ## Quick example
61
+
62
+ ```python
63
+ import reprobate
64
+
65
+ reprobate.render({"name": "alice", "scores": [98, 87, 95, 72, 88]}, 60)
66
+ # "{'name': 'alice', 'scores': [98, 87, 95, 72, 88]}"
67
+
68
+ reprobate.render({"name": "alice", "scores": [98, 87, 95, 72, 88]}, 30)
69
+ # "{'name': 'alice', ...1 more}"
70
+
71
+ reprobate.render(list(range(1000)), 40)
72
+ # "[0, 1, 2, 3, ...996 more]"
73
+ ```
74
+
75
+ ## Policies
76
+
77
+ ```python
78
+ from dataclasses import dataclass
79
+
80
+ @dataclass
81
+ class Agent:
82
+ desc: str = "A very long description that eats the budget"
83
+ important_note: str = "critical info here"
84
+ status: str = "running"
85
+ config: dict = None
86
+ history: list = None
87
+
88
+ # Greedy: first fields get full detail
89
+ reprobate.render(agent, 100, policy="greedy")
90
+ # "Agent(desc='A very long description that eats the budget', important_note=<str(18)>, ...3 more)"
91
+
92
+ # Even: all fields get comparable detail
93
+ reprobate.render(agent, 100, policy="even")
94
+ # "Agent(desc='A very long...', important_note='critical info...', status='running', ...2 more)"
95
+ ```
96
+
97
+ ## Custom renderers
98
+
99
+ Register a renderer for any type:
100
+
101
+ ```python
102
+ @reprobate.register(MyType)
103
+ def render_my_type(obj: MyType, budget: int) -> str:
104
+ return f"MyType({obj.key})"[:budget]
105
+ ```
106
+
107
+ Or implement the protocol directly:
108
+
109
+ ```python
110
+ class MyType:
111
+ def __budget_repr__(self, budget: int) -> str:
112
+ return f"MyType({self.key})"[:budget]
113
+ ```
114
+
115
+ For renderers that recurse into child objects, use `render_child` (inherits policy and cycle detection) and `render_attrs` (standard `TypeName(key=val, ...)` pattern):
116
+
117
+ ```python
118
+ from reprobate import register, render_child, render_attrs
119
+
120
+ @register(MyContainer)
121
+ def render_my_container(obj: MyContainer, budget: int) -> str:
122
+ # render_child for recursive rendering
123
+ inner = render_child(obj.value, budget - 10)
124
+ return f"MyContainer({inner})"
125
+
126
+ @register(MyModel)
127
+ def render_my_model(obj: MyModel, budget: int) -> str:
128
+ # render_attrs for the standard object pattern
129
+ attrs = {"name": obj.name, "data": obj.data}
130
+ return render_attrs(attrs, "MyModel", budget)
131
+ ```
132
+
133
+ ## Supported types
134
+
135
+ | Category | Types | Behavior |
136
+ |----------|-------|----------|
137
+ | Primitives | `None`, `bool`, `int`, `float` | `repr()`, truncated with `...` if needed |
138
+ | Strings | `str`, `bytes` | Quoted, truncated with `...` preserving quotes |
139
+ | Containers | `list`, `tuple`, `set`, `frozenset` | Head items + `...N more`, tail peek when budget allows |
140
+ | Dicts | `dict` | Key-value pairs + `...N more` |
141
+ | Collections | `deque`, `defaultdict`, `Counter` | Type-aware wrappers (factory name, most-common order) |
142
+ | Structured | `dataclass`, `namedtuple` | Field-aware decomposition, respects `repr=False` |
143
+ | Objects | anything with `__dict__` | Attribute decomposition, public attrs only |
144
+ | Optional | numpy, pandas, polars, pyarrow, Pillow, pydantic | Shape/dtype/columns summary (auto-activates when lib is installed) |
145
+
146
+ ## Development
147
+
148
+ ```bash
149
+ uv sync --extra dev
150
+ uv run pytest
151
+ ```
@@ -0,0 +1,116 @@
1
+ # reprobate 🖨️
2
+
3
+ Budget-controlled repr for Python objects.
4
+
5
+ Renders any Python object into a string that fits within a character budget. Nested structures degrade gracefully: full values, then type stubs, then counts. Zero dependencies. Pluggable via a type registry and a `__budget_repr__` protocol.
6
+
7
+ ## Features
8
+
9
+ - **Hard budget guarantee** -- output is always `<= budget` characters
10
+ - **Three-phase degradation** -- full render, then `name=<type(len)>` stubs, then `...N more` counts
11
+ - **Greedy and even policies** -- prioritize depth (first fields in detail) or breadth (all fields equally)
12
+ - **Cycle detection** -- circular references render as `<...>` instead of stack overflows
13
+ - **Type registry** -- `@register(MyType)` for custom budget-aware renderers
14
+ - **Protocol method** -- `__budget_repr__(self, budget)` on any class
15
+ - **Optional extensions** -- arrow, numpy, pandas, pil, polars, pydantic renderers (guarded imports, zero cost if absent)
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ pip install reprobate
21
+ ```
22
+
23
+ Zero dependencies. Optional renderers activate automatically when their libraries are already installed (numpy, pandas, polars, pyarrow, Pillow, pydantic).
24
+
25
+ ## Quick example
26
+
27
+ ```python
28
+ import reprobate
29
+
30
+ reprobate.render({"name": "alice", "scores": [98, 87, 95, 72, 88]}, 60)
31
+ # "{'name': 'alice', 'scores': [98, 87, 95, 72, 88]}"
32
+
33
+ reprobate.render({"name": "alice", "scores": [98, 87, 95, 72, 88]}, 30)
34
+ # "{'name': 'alice', ...1 more}"
35
+
36
+ reprobate.render(list(range(1000)), 40)
37
+ # "[0, 1, 2, 3, ...996 more]"
38
+ ```
39
+
40
+ ## Policies
41
+
42
+ ```python
43
+ from dataclasses import dataclass
44
+
45
+ @dataclass
46
+ class Agent:
47
+ desc: str = "A very long description that eats the budget"
48
+ important_note: str = "critical info here"
49
+ status: str = "running"
50
+ config: dict = None
51
+ history: list = None
52
+
53
+ # Greedy: first fields get full detail
54
+ reprobate.render(agent, 100, policy="greedy")
55
+ # "Agent(desc='A very long description that eats the budget', important_note=<str(18)>, ...3 more)"
56
+
57
+ # Even: all fields get comparable detail
58
+ reprobate.render(agent, 100, policy="even")
59
+ # "Agent(desc='A very long...', important_note='critical info...', status='running', ...2 more)"
60
+ ```
61
+
62
+ ## Custom renderers
63
+
64
+ Register a renderer for any type:
65
+
66
+ ```python
67
+ @reprobate.register(MyType)
68
+ def render_my_type(obj: MyType, budget: int) -> str:
69
+ return f"MyType({obj.key})"[:budget]
70
+ ```
71
+
72
+ Or implement the protocol directly:
73
+
74
+ ```python
75
+ class MyType:
76
+ def __budget_repr__(self, budget: int) -> str:
77
+ return f"MyType({self.key})"[:budget]
78
+ ```
79
+
80
+ For renderers that recurse into child objects, use `render_child` (inherits policy and cycle detection) and `render_attrs` (standard `TypeName(key=val, ...)` pattern):
81
+
82
+ ```python
83
+ from reprobate import register, render_child, render_attrs
84
+
85
+ @register(MyContainer)
86
+ def render_my_container(obj: MyContainer, budget: int) -> str:
87
+ # render_child for recursive rendering
88
+ inner = render_child(obj.value, budget - 10)
89
+ return f"MyContainer({inner})"
90
+
91
+ @register(MyModel)
92
+ def render_my_model(obj: MyModel, budget: int) -> str:
93
+ # render_attrs for the standard object pattern
94
+ attrs = {"name": obj.name, "data": obj.data}
95
+ return render_attrs(attrs, "MyModel", budget)
96
+ ```
97
+
98
+ ## Supported types
99
+
100
+ | Category | Types | Behavior |
101
+ |----------|-------|----------|
102
+ | Primitives | `None`, `bool`, `int`, `float` | `repr()`, truncated with `...` if needed |
103
+ | Strings | `str`, `bytes` | Quoted, truncated with `...` preserving quotes |
104
+ | Containers | `list`, `tuple`, `set`, `frozenset` | Head items + `...N more`, tail peek when budget allows |
105
+ | Dicts | `dict` | Key-value pairs + `...N more` |
106
+ | Collections | `deque`, `defaultdict`, `Counter` | Type-aware wrappers (factory name, most-common order) |
107
+ | Structured | `dataclass`, `namedtuple` | Field-aware decomposition, respects `repr=False` |
108
+ | Objects | anything with `__dict__` | Attribute decomposition, public attrs only |
109
+ | Optional | numpy, pandas, polars, pyarrow, Pillow, pydantic | Shape/dtype/columns summary (auto-activates when lib is installed) |
110
+
111
+ ## Development
112
+
113
+ ```bash
114
+ uv sync --extra dev
115
+ uv run pytest
116
+ ```
@@ -0,0 +1,63 @@
1
+ [project]
2
+ name = "reprobate"
3
+ version = "0.1.0"
4
+ description = "Budget-controlled repr for Python objects."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ authors = [
8
+ {name = "ashenfad"},
9
+ ]
10
+ keywords = ["repr", "pretty-print", "budget", "truncation", "llm"]
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Intended Audience :: Developers",
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.10",
16
+ "Programming Language :: Python :: 3.11",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
19
+ "Programming Language :: Python :: 3.14",
20
+ "Topic :: Software Development :: Libraries :: Python Modules",
21
+ ]
22
+ requires-python = ">=3.10"
23
+
24
+ dependencies = []
25
+
26
+ [project.optional-dependencies]
27
+ dev = [
28
+ "ruff",
29
+ "pre-commit",
30
+ "pytest",
31
+ "pytest-timeout",
32
+ ]
33
+ test = [
34
+ "pytest",
35
+ "pytest-timeout",
36
+ "numpy",
37
+ "pandas",
38
+ "Pillow",
39
+ "polars",
40
+ "pyarrow",
41
+ "pydantic",
42
+ ]
43
+
44
+ [tool.ruff]
45
+ line-length = 88
46
+
47
+ [tool.ruff.lint]
48
+ select = ["E4", "E7", "E9", "F", "I"]
49
+ ignore = ["E731"]
50
+
51
+ [tool.pytest.ini_options]
52
+ testpaths = ["tests"]
53
+ pythonpath = ["."]
54
+
55
+ [build-system]
56
+ requires = ["setuptools>=61.0", "wheel"]
57
+ build-backend = "setuptools.build_meta"
58
+
59
+ [tool.setuptools]
60
+ packages = {find = {where = ["./"], exclude = ["tests*"]}}
61
+
62
+ [tool.setuptools.package-data]
63
+ reprobate = ["py.typed"]
@@ -0,0 +1,22 @@
1
+ """reprobate: Budget-controlled repr for Python objects."""
2
+
3
+ from .core import Policy, render, render_attrs, render_child
4
+ from .registry import register
5
+
6
+ __all__ = [
7
+ "Policy",
8
+ "register",
9
+ "render",
10
+ "render_attrs",
11
+ "render_child",
12
+ ]
13
+
14
+ # Auto-register optional type renderers when their deps are available.
15
+ from . import (
16
+ ext_arrow, # noqa: F401
17
+ ext_numpy, # noqa: F401
18
+ ext_pandas, # noqa: F401
19
+ ext_pil, # noqa: F401
20
+ ext_polars, # noqa: F401
21
+ ext_pydantic, # noqa: F401
22
+ )