reprobate 🖨️
Budget-controlled repr for Python objects.
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.
Features
- Hard budget guarantee -- output is always
<= budgetcharacters - Three-phase degradation -- full render, then
name=<type(len)>stubs, then...N morecounts - Greedy and even policies -- prioritize depth (first fields in detail) or breadth (all fields equally)
- Uniform collapse -- sequences of one repeated value render as the lossless product form
[0.0] * 97 - Bounded type inference -- exact or best-effort aggregate hints such as
<list[str](200)>, with complete sample values when space allows:<list[{'id': int}](80): {'id': 0}, ...> - Cycle detection -- circular references render as
<...>instead of stack overflows - Type registry --
@register(MyType)for custom budget-aware renderers - Protocol method --
__budget_repr__(self, budget)on any class - Optional extensions -- typed table/array summaries for Arrow, NumPy, pandas, Polars, Pillow, and Pydantic (guarded imports, zero cost if absent)
Install
pip install reprobate
Zero dependencies. Optional renderers activate automatically when their libraries are already installed (numpy, pandas, polars, pyarrow, Pillow, pydantic).
Quick example
import reprobate
reprobate.render({"name": "alice", "scores": [98, 87, 95, 72, 88]}, 60)
# "{'name': 'alice', 'scores': [98, 87, 95, 72, 88]}"
reprobate.render({"name": "alice", "scores": [98, 87, 95, 72, 88]}, 30)
# "{'name': 'alice', ...1 more}"
reprobate.render(list(range(1000)), 40)
# "[0, 1, 2, 3, 4, 5, 6, 7, 8, ...991 more]"
Policies
from dataclasses import dataclass
@dataclass
class Agent:
desc: str = "A very long description that eats the budget"
important_note: str = "critical info here"
status: str = "running"
config: dict = None
history: list = None
agent = Agent()
# Greedy: first fields get full detail
reprobate.render(agent, 100, policy="greedy")
# "Agent(desc='A very long d...', important_note=<str(18)>, status=<str(7)>, config=None, history=None)"
# Even: all fields get comparable detail
reprobate.render(agent, 100, policy="even")
# "Agent(desc='A very l...', important_note='critical...', status='running', config=None, history=None)"
"even" uses max-min allocation among visible siblings. A bounded planning probe
identifies children whose complete representation needs less than their initial
share, then redistributes the unused characters among siblings that can still
improve. Opaque custom renderers are not called speculatively.
Inference
Aggregate type hints are controlled independently from budget allocation:
values = ["alice" * 30] * 1000
reprobate.render(values, 25)
# "<list[str](1000)>"
reprobate.render(values, 25, inference="exact")
# "<list(1000)>" -- too large for exhaustive inspection
reprobate.render(values, 25, inference="off")
# "[<str(150)>, ...999 more]"
result = {"users": ["alice" * 30] * 200, "cursor": "abc" * 100}
reprobate.render(result, 42)
# "<{'users': list[str], 'cursor': str}>"
"best_effort" is the default and uses bounded sampling for large containers.
"exact" emits aggregate types only after exhaustive bounded inspection; "off"
disables aggregate runtime inference. Type expressions are diagnostic hints, not
validation guarantees.
Small string-keyed mappings are treated as fixed records, so their compact schemas
retain the association between each literal key and its value type. Larger or
non-string-keyed mappings use dict[key_type, value_type] summaries instead.
Custom renderers
Register a renderer for any type:
@reprobate.register(MyType)
def render_my_type(obj: MyType, budget: int) -> str:
return f"MyType({obj.key})"[:budget]
Or implement the protocol directly:
class MyType:
def __budget_repr__(self, budget: int) -> str:
return f"MyType({self.key})"[:budget]
For renderers that recurse into child objects, use render_child (inherits policy and cycle detection) and render_attrs (standard TypeName(key=val, ...) pattern):
from reprobate import register, render_child, render_attrs
@register(MyContainer)
def render_my_container(obj: MyContainer, budget: int) -> str:
# render_child for recursive rendering
inner = render_child(obj.value, budget - 10)
return f"MyContainer({inner})"
@register(MyModel)
def render_my_model(obj: MyModel, budget: int) -> str:
# render_attrs for the standard object pattern
attrs = {"name": obj.name, "data": obj.data}
return render_attrs(attrs, "MyModel", budget)
Part of the agex stack
reprobate renders agent workspace objects for LLM context windows in agex, fitting complex types like DataFrames and nested structures within token budgets.
Supported types
| Category | Types | Behavior |
|---|---|---|
| Primitives | None, bool, int, float |
repr(), or a <int>-style stub when it cannot fit |
| Strings | str, bytes |
Quoted, escaped previews with ..., plus length metadata when space allows: <str(150): 'xxx...'> |
| Buffers | bytearray, array.array, memoryview |
repr() when it fits, else a sized preview of the leading bytes or elements: <bytearray(4096): b'\x00...'>, <array[d](500): 0.5, ...>; byte views show their contents, <memoryview(5): b'hello'>, and other views their format and shape, <memoryview[i](3, 4)> |
| Containers | list, tuple, set, frozenset |
Head items + ...N more, schema summaries when items cannot fit |
| Dicts | dict |
Key-value pairs + ...N more; subclasses keep their own repr |
| Collections | deque, defaultdict, Counter |
Type-aware wrappers (factory name, most-common order) |
| Structured | dataclass, namedtuple |
Field-aware decomposition, respects repr=False |
| Objects | anything with __dict__ or __slots__ |
Attribute decomposition, public attrs only |
| Optional | numpy, pandas, polars, pyarrow, Pillow, pydantic | Shape, dtype, typed-column schema, and bounded value or leading-row summaries such as DataFrame(3x2, {'name': str, 'score': int64}, [('ada', 7), ...2 more]) (auto-activates when installed) |
| numpy scalars | np.int64, np.float32, np.str_, ... |
Render as their builtin value (3, not np.int64(3)); extended precision and datetimes keep their own repr |
Development
uv sync --extra dev
uv run pytest
Metadata
Release files for reprobate 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| reprobate-0.1.6.tar.gz | 44.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| reprobate-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 76.7 kB
Release files / reprobate-0.1.6.tar.gz
| Download URL | reprobate-0.1.6.tar.gz |
|---|---|
| Size | 44.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76eca7c9d0c2748703f3fd0ca3d91ccd279aff20189fda14b98a75407b01a24f
|
|
BLAKE2b-256 checksum How to use checksums |
419e546ae9a4fdbae981517cacef9020a06c3ef34803e7868d2e588dd894f7e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Release files / reprobate-0.1.6-py3-none-any.whl
| Download URL | reprobate-0.1.6-py3-none-any.whl |
|---|---|
| Size | 31.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c26094ada54e5c2441ee4dfe46a793150ad180388fbaa156d62070e93364a005
|
|
BLAKE2b-256 checksum How to use checksums |
e6fe0976f2868214f4cf2f18ae2776f50f1dea21d1c8ac1c747470b83f4983a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Security for reprobate 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.