Skip to main content

Create __repr__ automatically or declaratively.

Project description


PyPI Version Documentation CI Status Coverage Python Version MIT License


$ pip install represent

Automatic Generation

from represent import autorepr

class Rectangle:
    def __init__(self, name, color, width, height): = name
        self.color = color
        self.width = width
        self.height = height

rect = Rectangle('Timothy', 'red', 15, 4.5)
Rectangle(name='Timothy', color='red', width=15, height=4.5)

Declarative Generation

from represent import ReprHelperMixin

class ContrivedExample(ReprHelperMixin, object):
    def __init__(self, description, radians, shape, color, miles):
        self.description = description
        self.degrees = radians * 180 / 3.141592654
        self.shape = shape
        self._color = color = 1.60934 * miles

    def _repr_helper_(self, r):
        r.positional_with_value(self.degrees * 3.141592654 / 180)
        r.keyword_from_attr('color', '_color')
        r.keyword_with_value('miles', / 1.60934)

ce = ContrivedExample('does something', 0.345, 'square', 'red', 22)

from IPython.lib.pretty import pprint
ContrivedExample('does something', 0.345, shape='square', color='red', miles=22.0)
ContrivedExample('does something',

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Represent, version 1.6.0.post0
Filename, size File type Python version Upload date Hashes
Filename, size Represent-1.6.0.post0.tar.gz (23.4 kB) File type Source Python version None Upload date Hashes View
Filename, size Represent-1.6.0.post0-py2.py3-none-any.whl (12.4 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page