Skip to main content

Python utilities for concise object representation

This library provides utilities to implement the __repr__ and ipython _repr_pretty_ methods to represent objects in a concise manner. The implementation is based on the class __init__ method signature, and will differentiate between positional and optional parameters in order to make the representation as succinct as possible.

These methods are intended to be used on simple classes that map all their constructor arguments to attributes. Also note that dataclasses already implement a similar __repr__ method by default.

Usage

To add a basic representation to a class you can overrides its __repr__ method with lazy_repr as follows:

from lazyrepr import lazy_repr

class MyClass:
    __repr__ = lazy_repr
    ...

To provide both __repr__ and ipython _repr_pretty_ for a class just inherit from ReprMixin

from lazyrepr import ReprMixin

class MyList(ReprMixin):
    def __init__(self, item=()):
        self.items = list(items)

lst = MyList(range(3))
print(lst)  # >>> MyList([0, 1, 2])

Examples

Examples notebooks are in the extras folder.

Installation

You can install this package with pip.

pip install lazyrepr
  • easyrepr Python decorator to automatically generate repr strings

Metadata

Release files for lazyrepr 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for lazyrepr 0.0.4
File Interpreter ABI Platform Actions
lazyrepr-0.0.4-py3-none-any.whl Python 3 none any Details for lazyrepr-0.0.4-py3-none-any.whl

Release files / lazyrepr-0.0.4-py3-none-any.whl

Download URL lazyrepr-0.0.4-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b18e44fa59274ef57e3b03b3dd38cb35e77bfcecd1cf8b21360623343a108b20
BLAKE2b-256 checksum
How to use checksums
9860bc7cdbb4e47579a4c57b009bb141593d85b11081920472f023b0092a537b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.0

Security for lazyrepr 0.0.4

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page