custom-repr


Namecustom-repr JSON
Version 2.2.0 PyPI version JSON
download
home_pageNone
SummaryA lightweight Python library to automatically generate clean __repr__ methods for all your user-declared classes.
upload_time2025-02-25 16:31:00
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseMIT
keywords repr string representation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Custom Repr Library

A lightweight Python library designed to offer a custom representation for user-defined classes. This library enables users to visualize class attributes and methods with enhanced formatting using the Rich library. Please be aware that this library employs monkey patching so it should be use with caution.

## Installation

To install the library, use pip:

```bash
pip install custom-repr
```

## Usage

### Basic Usage

To use the custom representation, simply import the library:

```python
import custom_repr

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def greet(self):
        return f"Hello, my name is {self.name}."

# Create an instance
person = Person("Alice", 30)

print(person) # The output will be: 
# Person => { name: "Alice", age: 30 }
# [ greet() ] 
```

### Configuration

You can configure the output format of the custom representation using the `custom_repr_config` function. This function allows you to choose whether to display attributes, methods, or both.

#### Function Signature

```python
from custom_repr import custom_repr_config

custom_repr_config(attributes=True, methods=True)
```

#### Examples

- **Show both attributes and methods** (default behavior):

  ```python
  custom_repr_config(True, True)
  ```

- **Show only attributes**:

  ```python
  custom_repr_config(True, False)
  ```

- **Show only methods**:

  ```python
  custom_repr_config(False, True)
  ```

- **Show only the class name**:

  ```python
  custom_repr_config(False, False)
  ```

### Example

```python
from custom_repr import custom_repr_config

# Configure to show only attributes
custom_repr_config(True, False)

class Car:
    def __init__(self, make, model):
        self.make = make
        self.model = model

    def drive(self):
        return "Vroom!"

car = Car("Toyota", "Corolla")
print(car) # Outputs: Car => { make: "Toyota", model: "Corolla" }

# Configure to show only the class name
custom_repr_config(False, False)
print(car)  # Outputs: Car
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "custom-repr",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "repr, string representation",
    "author": null,
    "author_email": "Pedro Fernandes da Silva <paca.fs@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/59/ed/9ee314de06d1bfd5f023df3fb58cc8507557d22c13a29af4cc6134653a0e/custom_repr-2.2.0.tar.gz",
    "platform": null,
    "description": "# Custom Repr Library\n\nA lightweight Python library designed to offer a custom representation for user-defined classes. This library enables users to visualize class attributes and methods with enhanced formatting using the Rich library. Please be aware that this library employs monkey patching so it should be use with caution.\n\n## Installation\n\nTo install the library, use pip:\n\n```bash\npip install custom-repr\n```\n\n## Usage\n\n### Basic Usage\n\nTo use the custom representation, simply import the library:\n\n```python\nimport custom_repr\n\nclass Person:\n    def __init__(self, name, age):\n        self.name = name\n        self.age = age\n\n    def greet(self):\n        return f\"Hello, my name is {self.name}.\"\n\n# Create an instance\nperson = Person(\"Alice\", 30)\n\nprint(person) # The output will be: \n# Person => { name: \"Alice\", age: 30 }\n# [ greet() ] \n```\n\n### Configuration\n\nYou can configure the output format of the custom representation using the `custom_repr_config` function. This function allows you to choose whether to display attributes, methods, or both.\n\n#### Function Signature\n\n```python\nfrom custom_repr import custom_repr_config\n\ncustom_repr_config(attributes=True, methods=True)\n```\n\n#### Examples\n\n- **Show both attributes and methods** (default behavior):\n\n  ```python\n  custom_repr_config(True, True)\n  ```\n\n- **Show only attributes**:\n\n  ```python\n  custom_repr_config(True, False)\n  ```\n\n- **Show only methods**:\n\n  ```python\n  custom_repr_config(False, True)\n  ```\n\n- **Show only the class name**:\n\n  ```python\n  custom_repr_config(False, False)\n  ```\n\n### Example\n\n```python\nfrom custom_repr import custom_repr_config\n\n# Configure to show only attributes\ncustom_repr_config(True, False)\n\nclass Car:\n    def __init__(self, make, model):\n        self.make = make\n        self.model = model\n\n    def drive(self):\n        return \"Vroom!\"\n\ncar = Car(\"Toyota\", \"Corolla\")\nprint(car) # Outputs: Car => { make: \"Toyota\", model: \"Corolla\" }\n\n# Configure to show only the class name\ncustom_repr_config(False, False)\nprint(car)  # Outputs: Car\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A lightweight Python library to automatically generate clean __repr__ methods for all your user-declared classes.",
    "version": "2.2.0",
    "project_urls": null,
    "split_keywords": [
        "repr",
        " string representation"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6fdba2716f0fd8ff31ebfbc9b7982f820cc389e5b28822a591cfd795c8ae6b40",
                "md5": "f3139450a4c59b03f9463426059c68a0",
                "sha256": "5fb34bfe78a0180b9ee467b2ef5fff91b7c21da575a85809ad937b6f5daead20"
            },
            "downloads": -1,
            "filename": "custom_repr-2.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f3139450a4c59b03f9463426059c68a0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5185,
            "upload_time": "2025-02-25T16:30:59",
            "upload_time_iso_8601": "2025-02-25T16:30:59.201309Z",
            "url": "https://files.pythonhosted.org/packages/6f/db/a2716f0fd8ff31ebfbc9b7982f820cc389e5b28822a591cfd795c8ae6b40/custom_repr-2.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "59ed9ee314de06d1bfd5f023df3fb58cc8507557d22c13a29af4cc6134653a0e",
                "md5": "a7c6409ff464b31ff4e48a38e785e2a1",
                "sha256": "a0992ea8f2b68fb9335b97277f7dc30838d3a761b9bb5796598b2b82cd05cfae"
            },
            "downloads": -1,
            "filename": "custom_repr-2.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a7c6409ff464b31ff4e48a38e785e2a1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4748,
            "upload_time": "2025-02-25T16:31:00",
            "upload_time_iso_8601": "2025-02-25T16:31:00.335798Z",
            "url": "https://files.pythonhosted.org/packages/59/ed/9ee314de06d1bfd5f023df3fb58cc8507557d22c13a29af4cc6134653a0e/custom_repr-2.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-25 16:31:00",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "custom-repr"
}
        
Elapsed time: 1.38612s