| Name | printo JSON |
| Version |
0.0.8
JSON |
| download |
| home_page | None |
| Summary | Print objects with data beautifully |
| upload_time | 2025-10-16 22:24:40 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.8 |
| license | None |
| keywords |
print
repr
serialization
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|

[](https://pepy.tech/project/printo)
[](https://pepy.tech/project/printo)
[](https://coveralls.io/github/pomponchik/printo?branch=main)
[](https://github.com/boyter/scc/)
[](https://hitsofcode.com/github/pomponchik/printo/view?branch=main)
[](https://github.com/pomponchik/printo/actions/workflows/tests_and_coverage.yml)
[](https://pypi.python.org/pypi/printo)
[](https://badge.fury.io/py/printo)
[](http://mypy-lang.org/)
[](https://github.com/astral-sh/ruff)
There is an implicit agreement among pythonists to create special [`__repr__`](https://docs.python.org/3/reference/datamodel.html#object.__repr__) methods for classes that return text as similar as possible to the piece of code where the specific object was constructed. `__repr__` of `1` returns "1", and repr of `None` returns "None". With this library, you can create your own classes, the objects of which will obey this rule.
## Table of contents
- [**Installation**](#installation)
- [**Basic usage**](#basic-usage)
- [**Filtering**](#filtering)
- [**Custom display of objects**](#custom-display-of-objects)
- [**Placeholders**](#placeholders)
## Installation
You can install [`dirstree`](https://pypi.python.org/pypi/printo) using pip:
```bash
pip install printo
```
You can also quickly try out this and other packages without having to install using [instld](https://github.com/pomponchik/instld).
## Basic usage
The main function in this library is `descript_data_object`, it returns a string representing what your object's initialization code should look like. There are 3 required positional parameters:
- The name of the class for which we are creating a representation.
- A `list` or `tuple` of positional arguments.
- A `dict` with named arguments, where the keys are the names of the arguments, and the values are any objects.
Here's a simple example of how it works:
```python
from printo import descript_data_object
print(descript_data_object('MyClassName', (1, 2, 'some text'), {'variable_name': 1, 'second_variable_name': 'kek'}))
#> MyClassName(1, 2, 'some text', variable_name=1, second_variable_name='kek')
```
## Filtering
You can prevent individual fields from being displayed. To do this, pass a `dict` as the `filters` parameter, in which the argument numbers (counting starts from 0) for positional arguments or the argument names for named arguments will be used as keys, and returning `bool` functions (each of them answers the question "whether to display this argument", where `True` means "yes" and `False` means "no") will be used as values:
```python
print(descript_data_object('MyClassName', (1, 2, 'some text'), {'variable_name': 1, 'second_variable_name': 'kek'}, filters={1: lambda x: False if x == 2 else True, 'second_variable_name': lambda x: False}))
#> MyClassName(1, 'some text', variable_name=1)
```
You can also save a few characters by specifying a function as a filter that automatically filters `None` of the values:
```python
from printo import not_none
print(descript_data_object('MyClassName', (1, None), {}, filters={1: not_none}))
#> MyClassName(1)
```
## Custom display of objects
By default, all your objects are serialized in the same way as the standard [`repr`](https://docs.python.org/3/library/functions.html#repr) function does. There are only 2 exceptions:
- Ordinary functions, in their case, instead of the usual text, just the function name is displayed.
- Lambda functions, just the `λ` symbol is displayed instead. This is done because there is no reliable way to display the source code of a lambda function in Python.
You can use your own function as a repr for all your objects, use the `serializator` parameter for this:
```python
print(
descript_data_object(
'MyClassName',
(1, 2, 'lol'),
{'variable_name': 1, 'second_variable_name': 'kek'},
serializator=lambda x: repr(x * 2),
)
)
#> MyClassName(2, 4, 'lollol', variable_name=2, second_variable_name='kekkek')
```
## Placeholders
For individual fields, you can pass predefined strings that will be displayed instead of the actual values. This can be useful, for example, to hide the values of secret fields when serializing objects.
Use the `placeholders` parameter for this by passing a dictionary there, where the keys are parameter names (for named parameters) or their numbers (for positional parameters, numbering starts from 0), and the values are strings:
```python
print(
descript_data_object(
'MySuperClass',
(1, 2, 'lol'),
{'variable_name': 1, 'second_variable_name': 'kek'},
placeholders={
1: '***',
'variable_name': '***',
},
)
)
#> MySuperClass(1, ***, 'lol', variable_name=***, second_variable_name='kek')
```
> 🤓 Please note that if you set a placeholder for a parameter, a [custom serializer](#custom-display-of-objects) will no longer be applied to it.
Raw data
{
"_id": null,
"home_page": null,
"name": "printo",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "print, repr, serialization",
"author": null,
"author_email": "Evgeniy Blinov <zheni-b@yandex.ru>",
"download_url": "https://files.pythonhosted.org/packages/04/d2/65f6d4d7f14fa8dfd6bf1c187dbce6dfc2a8f8c8f2b00f73215f53bcdd5b/printo-0.0.8.tar.gz",
"platform": null,
"description": "\n\n[](https://pepy.tech/project/printo)\n[](https://pepy.tech/project/printo)\n[](https://coveralls.io/github/pomponchik/printo?branch=main)\n[](https://github.com/boyter/scc/)\n[](https://hitsofcode.com/github/pomponchik/printo/view?branch=main)\n[](https://github.com/pomponchik/printo/actions/workflows/tests_and_coverage.yml)\n[](https://pypi.python.org/pypi/printo)\n[](https://badge.fury.io/py/printo)\n[](http://mypy-lang.org/)\n[](https://github.com/astral-sh/ruff)\n\nThere is an implicit agreement among pythonists to create special [`__repr__`](https://docs.python.org/3/reference/datamodel.html#object.__repr__) methods for classes that return text as similar as possible to the piece of code where the specific object was constructed. `__repr__` of `1` returns \"1\", and repr of `None` returns \"None\". With this library, you can create your own classes, the objects of which will obey this rule.\n\n\n## Table of contents\n\n- [**Installation**](#installation)\n- [**Basic usage**](#basic-usage)\n- [**Filtering**](#filtering)\n- [**Custom display of objects**](#custom-display-of-objects)\n- [**Placeholders**](#placeholders)\n\n\n## Installation\n\nYou can install [`dirstree`](https://pypi.python.org/pypi/printo) using pip:\n\n```bash\npip install printo\n```\n\nYou can also quickly try out this and other packages without having to install using [instld](https://github.com/pomponchik/instld).\n\n\n## Basic usage\n\nThe main function in this library is `descript_data_object`, it returns a string representing what your object's initialization code should look like. There are 3 required positional parameters:\n\n- The name of the class for which we are creating a representation.\n- A `list` or `tuple` of positional arguments.\n- A `dict` with named arguments, where the keys are the names of the arguments, and the values are any objects.\n\nHere's a simple example of how it works:\n\n```python\nfrom printo import descript_data_object\n\nprint(descript_data_object('MyClassName', (1, 2, 'some text'), {'variable_name': 1, 'second_variable_name': 'kek'}))\n#> MyClassName(1, 2, 'some text', variable_name=1, second_variable_name='kek')\n```\n\n\n## Filtering\n\nYou can prevent individual fields from being displayed. To do this, pass a `dict` as the `filters` parameter, in which the argument numbers (counting starts from 0) for positional arguments or the argument names for named arguments will be used as keys, and returning `bool` functions (each of them answers the question \"whether to display this argument\", where `True` means \"yes\" and `False` means \"no\") will be used as values:\n\n```python\nprint(descript_data_object('MyClassName', (1, 2, 'some text'), {'variable_name': 1, 'second_variable_name': 'kek'}, filters={1: lambda x: False if x == 2 else True, 'second_variable_name': lambda x: False}))\n#> MyClassName(1, 'some text', variable_name=1)\n```\n\nYou can also save a few characters by specifying a function as a filter that automatically filters `None` of the values:\n\n```python\nfrom printo import not_none\n\nprint(descript_data_object('MyClassName', (1, None), {}, filters={1: not_none}))\n#> MyClassName(1)\n```\n\n\n## Custom display of objects\n\nBy default, all your objects are serialized in the same way as the standard [`repr`](https://docs.python.org/3/library/functions.html#repr) function does. There are only 2 exceptions:\n\n- Ordinary functions, in their case, instead of the usual text, just the function name is displayed.\n- Lambda functions, just the `\u03bb` symbol is displayed instead. This is done because there is no reliable way to display the source code of a lambda function in Python.\n\nYou can use your own function as a repr for all your objects, use the `serializator` parameter for this:\n\n```python\nprint(\n descript_data_object(\n 'MyClassName',\n (1, 2, 'lol'),\n {'variable_name': 1, 'second_variable_name': 'kek'},\n serializator=lambda x: repr(x * 2),\n )\n)\n#> MyClassName(2, 4, 'lollol', variable_name=2, second_variable_name='kekkek')\n```\n\n\n## Placeholders\n\nFor individual fields, you can pass predefined strings that will be displayed instead of the actual values. This can be useful, for example, to hide the values of secret fields when serializing objects.\n\nUse the `placeholders` parameter for this by passing a dictionary there, where the keys are parameter names (for named parameters) or their numbers (for positional parameters, numbering starts from 0), and the values are strings:\n\n```python\nprint(\n descript_data_object(\n 'MySuperClass',\n (1, 2, 'lol'),\n {'variable_name': 1, 'second_variable_name': 'kek'},\n placeholders={\n 1: '***',\n 'variable_name': '***',\n },\n )\n)\n#> MySuperClass(1, ***, 'lol', variable_name=***, second_variable_name='kek')\n```\n\n> \ud83e\udd13 Please note that if you set a placeholder for a parameter, a [custom serializer](#custom-display-of-objects) will no longer be applied to it.\n",
"bugtrack_url": null,
"license": null,
"summary": "Print objects with data beautifully",
"version": "0.0.8",
"project_urls": {
"Source": "https://github.com/pomponchik/printo",
"Tracker": "https://github.com/pomponchik/printo/issues"
},
"split_keywords": [
"print",
" repr",
" serialization"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "3106ea67cf10ff1d0d27d2fa78f72b5a3e59bec80c01408673d5aaefc3e39a7f",
"md5": "f4e83d43ce74dffca8114c05f72ac5e0",
"sha256": "fc70b1679782e656308ff8385a7aa3d8ea6b60a7f0f3b05c11cf8c20c641d8d9"
},
"downloads": -1,
"filename": "printo-0.0.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f4e83d43ce74dffca8114c05f72ac5e0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5836,
"upload_time": "2025-10-16T22:24:39",
"upload_time_iso_8601": "2025-10-16T22:24:39.223759Z",
"url": "https://files.pythonhosted.org/packages/31/06/ea67cf10ff1d0d27d2fa78f72b5a3e59bec80c01408673d5aaefc3e39a7f/printo-0.0.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "04d265f6d4d7f14fa8dfd6bf1c187dbce6dfc2a8f8c8f2b00f73215f53bcdd5b",
"md5": "2f2609fe5d56e2cd7df487f3317efd61",
"sha256": "cea2ad08084bb46ab75c811f2d4b34267bf5c6f18bf288ad9ec9291bb2139f8f"
},
"downloads": -1,
"filename": "printo-0.0.8.tar.gz",
"has_sig": false,
"md5_digest": "2f2609fe5d56e2cd7df487f3317efd61",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 5178,
"upload_time": "2025-10-16T22:24:40",
"upload_time_iso_8601": "2025-10-16T22:24:40.707436Z",
"url": "https://files.pythonhosted.org/packages/04/d2/65f6d4d7f14fa8dfd6bf1c187dbce6dfc2a8f8c8f2b00f73215f53bcdd5b/printo-0.0.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-16 22:24:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pomponchik",
"github_project": "printo",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "printo"
}