No project description provided
Project description
rich-objects
This is a small set of tools to help provide easy to use, flexible tools for display complex objects for a CLI.
Getting started
The project has been published to PyPi, so you should be able to install it with something like one of the following (depending on how you do Python package management):
% pip install rich-objects
% poetry add rich-objects
The sections below provide a brief description with links to more examples and details.
Background
This module extends the rich module to provide pretty printing of complex data objects. The most common use case is a CLI that displays the json/yaml data that is returned to a CLI client in several different formats.
The easiest way to leverage this library is using the display() function. You can provide a fmt and style to provide different means of displaying the data.
Here are some of the lower level elements:
OutputFormatandOutputSyleare enums suitable to use as a CLI argument to support different displaysRichTableclass is a thin wrapper derived fromrich.Table. It contains some default formatting for the tables, since it becomes confusing when tables are nested.- Added several functions starting with
rich_table_factory()to create aRichTablewith appropriate nesting based on the data returned by the data in the object. - The
console_factory()is the default means for printing the output, but this just sets therich.Consolewidth.
Examples
In general, this can be used in any enviroment where CLI output is used.
Typer Example
Here's a simple Python example to leverage the new code:
#!/usr/bin/env python3
from typer import Typer
from rich_objects import OutputFormat, display
DATA = [
{"name": "sna", "prop1": 1, "prop B": None, "blah": "zay"},
{
"name": "foo",
"prop2": 2,
"prop B": True,
},
{
"name": "bar",
1: "inverse",
},
]
app = Typer()
@app.command()
def print_data(
output_fmt: OutputFormat = OutputFormat.TEXT,
output_style: OutputStyle = OutputStyle.ALL,
indent: int = 2,
):
data = DATA # TODO: figure out how to get your data here
display(data, fmt=output_fmt, style=output_style, indent=indent)
if __name__ == "__main__":
app()
Here's some sample output:
(.venv) > ./example.py
┏━━━━━━┳━━━━━━━━━━━━━━━━┓
┃ Name ┃ Properties ┃
┡━━━━━━╇━━━━━━━━━━━━━━━━┩
│ sna │ prop1 1 │
│ │ prop B None │
│ │ blah zay │
├──────┼────────────────┤
│ foo │ prop2 2 │
│ │ prop B True │
├──────┼────────────────┤
│ bar │ 1 inverse │
└──────┴────────────────┘
Found 3 items
(.venv) > ./example.py --output-fmt json
[
{
"name": "sna",
"prop1": 1,
"prop B": null,
"blah": "zay"
},
{
"name": "foo",
"prop2": 2,
"prop B": true
},
{
"name": "bar",
"1": "inverse"
}
]
(.venv) > ./example.py --output-fmt yaml
- blah: zay
name: sna
prop B: null
prop1: 1
- name: foo
prop B: true
prop2: 2
- name: bar
1: inverse
(.venv) >
Contributing
This project is just getting going... More development instructions will be added later. If you have any suggestions, please email Rick directly (rickwporter@gmail.com).
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rich_objects-0.1.3.tar.gz.
File metadata
- Download URL: rich_objects-0.1.3.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fde425dce4f32c5962059d95abf144322bbab76ff2303a5aebe64244912ae974
|
|
| MD5 |
95cebe549d36d9902598115f6c26eef0
|
|
| BLAKE2b-256 |
641c0bbaaecdcb2a213c310f9911b2c1e65d532a1c8a8236cd608a6a6fceaf97
|
Provenance
The following attestation bundles were made for rich_objects-0.1.3.tar.gz:
Publisher:
pypi_publish.yaml on rickwporter/rich-objects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rich_objects-0.1.3.tar.gz -
Subject digest:
fde425dce4f32c5962059d95abf144322bbab76ff2303a5aebe64244912ae974 - Sigstore transparency entry: 766509195
- Sigstore integration time:
-
Permalink:
rickwporter/rich-objects@92b54d33e213a321d76ebc8ee3f31e677c102242 -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/rickwporter
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_publish.yaml@92b54d33e213a321d76ebc8ee3f31e677c102242 -
Trigger Event:
release
-
Statement type:
File details
Details for the file rich_objects-0.1.3-py3-none-any.whl.
File metadata
- Download URL: rich_objects-0.1.3-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8c5b6aa87acbfb73d65a1ab2a76deaf20abbb5b21c87fa6e5e9f1ec0bb99a24
|
|
| MD5 |
2c0bcc00b8664e4a476396df0a70bcb7
|
|
| BLAKE2b-256 |
dcaa2e5083b8ce07edf8ec927b9457945be74ea666c5c18dcf139058dda3c0e3
|
Provenance
The following attestation bundles were made for rich_objects-0.1.3-py3-none-any.whl:
Publisher:
pypi_publish.yaml on rickwporter/rich-objects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rich_objects-0.1.3-py3-none-any.whl -
Subject digest:
d8c5b6aa87acbfb73d65a1ab2a76deaf20abbb5b21c87fa6e5e9f1ec0bb99a24 - Sigstore transparency entry: 766509200
- Sigstore integration time:
-
Permalink:
rickwporter/rich-objects@92b54d33e213a321d76ebc8ee3f31e677c102242 -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/rickwporter
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_publish.yaml@92b54d33e213a321d76ebc8ee3f31e677c102242 -
Trigger Event:
release
-
Statement type: