Skip to main content

Create __repr__ automatically or declaratively.

Project description

Represent

PyPI Version Documentation CI Status Coverage Python Version MIT License

Installation

$ pip install represent

Automatic Generation

from represent import autorepr


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

rect = Rectangle('Timothy', 'red', 15, 4.5)
print(rect)
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
        self.km = 1.60934 * miles

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

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

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

Project details


Download files

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

Source Distribution

represent-2.2.0.tar.gz (71.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

represent-2.2.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file represent-2.2.0.tar.gz.

File metadata

  • Download URL: represent-2.2.0.tar.gz
  • Upload date:
  • Size: 71.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for represent-2.2.0.tar.gz
Algorithm Hash digest
SHA256 403daa7f8360390b84b143b7bf1dd720965a3e93a234994923c7123cc55d5fe1
MD5 750759bf7d15d49c394c1ab8d0f77905
BLAKE2b-256 51f0965dfb05568ec7d56cd37b8fc75eb35ed159c0e9a80309019155511046ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for represent-2.2.0.tar.gz:

Publisher: python-publish.yml on RazerM/represent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file represent-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: represent-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for represent-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 317db78ccb92cdbd5cd836652b34812385a12610f825d9d950874d2a39fd0f02
MD5 063d06705f5b8cfd5c6bbff0924023fb
BLAKE2b-256 835a373677ed4e15b094365c68f6f0e825f972d6b0e2976312b47ac794fcbb34

See more details on using hashes here.

Provenance

The following attestation bundles were made for represent-2.2.0-py3-none-any.whl:

Publisher: python-publish.yml on RazerM/represent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page