Registry / serialization / objprint

objprint

JSON →
library0.3.0pypypi✓ verified 21d ago

objprint is a Python library designed to print Python objects in a human-readable format, simplifying debugging and inspection. It provides a primary function `op()` and a decorator `@add_objprint` for custom classes. The library is actively maintained, with its current version being 0.3.0, and has a fairly regular release cadence addressing new Python versions and adding features.

pip install objprint
INSTALL
IMPORT
SIG · OBJPRINT
O
objprint
serializationpythonv0.3.0
Install
1.5s avg
Import
58ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.0 · 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
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.060s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.056s · 19MB
16MB installed
● package 16MB
Code
Verified usage

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

op
from objprint import op
from objprint import objprint
The primary printing function was renamed from `objprint` to `op` in version 0.1.2.
add_objprint
from objprint import add_objprint
config
from objprint import config
Used for global configuration of objprint behavior.

This quickstart demonstrates how to use the `op()` function to print instances of both standard Python classes and classes decorated with `@add_objprint`. It shows how `objprint` automatically formats object attributes for readability.

from objprint import op, add_objprint class MyObject: def __init__(self, name, value): self.name = name self.value = value self.items = [1, {'a': 2}, 'hello'] def get_info(self): return f"{self.name}: {self.value}" @add_objprint class AnotherObject: def __init__(self, id_val): self.id = id_val self.nested_obj = MyObject("Nested", 99) # Print a standard object my_instance = MyObject("Test", 42) op(my_instance) # Print an object decorated with @add_objprint another_instance = AnotherObject(123) op(another_instance) # Example of global configuration (optional) # from objprint import config # config(indent=4, color=False) # op(my_instance)
Debug
Known issues
breakingThe primary printing function was renamed from `objprint` to `op` in version 0.1.2. Code using `objprint(my_object)` will break.
fix
Change all calls from `objprint(obj)` to `op(obj)` and imports from `from objprint import objprint` to `from objprint import op`.
affects: <0.1.2 to >=0.1.2
gotchaObjprint includes recursion handling to prevent infinite loops when printing circularly referenced objects. This means deeply nested or self-referential structures might not be fully expanded by default.
fix
While `objprint` prioritizes preventing crashes, you can configure recursion depth and behavior if needed, though this is generally not recommended for typical use cases. See `objprint.config(skip_recursion=...)`.
affects: >=0.1.4
gotchaPrior to version 0.2.2, objprint used `__dict__` to retrieve attributes, which might not show all attributes for objects that don't primarily store state in `__dict__` (e.g., objects using `__slots__` or C-extensions).
fix
Upgrade to version 0.2.2 or newer, which uses `dir()` to list attributes, providing a more comprehensive view.
affects: <0.2.2
gotchaThe `print_methods` feature (introduced in 0.2.0) can significantly increase output verbosity by including callable methods. This is off by default, but if enabled, can make output overwhelming.
fix
Manage output verbosity by configuring `objprint.config(print_methods=False)` or ensure you only enable it when method inspection is specifically needed.
affects: >=0.2.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'objprint'
The objprint library has not been installed in the current Python environment.
fix
Install the library using pip: `pip install objprint`
AttributeError: module 'objprint' has no attribute 'op'
The 'op' function is typically imported directly from the 'objprint' module, not accessed as an attribute of the module itself. Users might try to call `objprint.op()` instead of `op()`.
fix
Import 'op' directly using `from objprint import op` and then call `op(your_object)`.
TypeError: op() missing 1 required positional argument: 'obj'
The `op()` function was called without passing any object to it, but it requires at least one object argument to print.
fix
Pass the object you intend to print as an argument to `op()`, for example: `op(my_instance)`.
objprint is disabled
The global printing functionality of objprint was explicitly disabled using `op.disable()` at some point in the code, preventing `op()` calls from producing output.
fix
Re-enable objprint globally by calling `op.enable()` before the `op()` call you expect to print. Alternatively, remove the `op.disable()` call if it was unintended.
Upgrade
Version history
0.3.0latest on PyPI · released Nov 9, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
objprint — pip install objprint · libregistry