Objprint - Pretty Print Python Objects

0.3.0 · active · verified Sun Apr 12

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.

Warnings

Install

Imports

Quickstart

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)

view raw JSON →