Skip to main content

crepr

Create a __repr__ for your python classes.

crepr is a Python script that takes a file name as a command-line argument, imports the specified module, and then adds or removes a __repr__ method for each class defined in the module. It uses the definition found in the __init__ method of the class to create a useful representation of the object. It is pronounced /kɹeɪpr/, like 🇳🇿 crêpe.

Have a look at the blog-post Love Your Representation for the rationale of this package.

Tests codecov pre-commit MyPy Black MIT License Python Version PyPI - Version Status

Features

  • Automatically generates __repr__ methods for all classes in a Python file
  • Uses the __init__ method's arguments to create a meaningful representation
  • Can add or remove __repr__ methods
  • Provides options to display the diff or apply changes directly to the file

Install

pip install crepr

Usage

To add a __repr__ method to all classes in a file:

crepr add <file_name> [--kwarg-splat "{}"] [--diff/--inline]

To remove the __repr__ method from all classes in a file:

crepr remove <file_name> [--diff/--inline]

Options

  • <file_name>: The name of the Python file to process.
  • --kwarg-splat: The string to use for the **kwargs splat (default: "{}").
  • --diff: Display the diff of the changes.
  • --inline: Apply the changes directly to the file.
  • --ignore-existing: Add __repr__ regardless if one exists

Example

Given the file tests/classes/kw_only_test.py with the contents:

class KwOnly:
    def __init__(self, name: str, *, age: int) -> None:
        self.name = name
        self.age = age

The command:

❯ crepr add tests/classes/kw_only_test.py

produces

class KwOnly:
    def __init__(self, name: str, *, age: int) -> None:
        self.name = name
        self.age = age

    def __repr__(self) -> str:
        """Create a string (c)representation for KwOnly."""
        return (f'{self.__class__.__module__}.{self.__class__.__name__}('
            f'name={self.name!r}, '
            f'age={self.age!r}, '
        ')')

The repr() of an instance of this class will be:

>>> from tests.classes.kw_only_test import KwOnly
>>> kwo = KwOnly('Christian', age=25)
>>> kwo
tests.classes.kw_only_test.KwOnly(name='Christian', age=25, )

Apply the changes to the file with:

❯ crepr add tests/classes/kw_only_test.py --inline

Give your representations some love.

❤️.__repr__(self) -> str:

Metadata

Release files for crepr 0.6.0

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

Source distribution (sdist)

Source distribution for crepr 0.6.0
File Size Uploaded
crepr-0.6.0.tar.gz 8.4 kB Details

Built distribution (wheel)

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

Total release size: 16.5 kB

Release files / crepr-0.6.0.tar.gz

Download URL crepr-0.6.0.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
48cfb22a937ba8b8ef114d60e211628035eb379a50c4d0c8653dfffff91aa561
BLAKE2b-256 checksum
How to use checksums
ea2952007be897dbdda5be8b4ea58a3ef914e2bc6505257dc9d969adbecf6987
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2025.

Transparency log

Release files / crepr-0.6.0-py3-none-any.whl

Download URL crepr-0.6.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4d968ca7680d04fadc0292cdecdf7d528ef44b3ed8d6fcde00fa1ba17c82b60
BLAKE2b-256 checksum
How to use checksums
0722c7e8b04dd8e257b9232b95359abf0b1403f5ed1c343d3e9a0320e85ee073
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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