Skip to main content

kuromon

PyPI version Python CI

Convert a list of dict, dataclass, Pydantic or POPO objects into a string represented table.

Requirements

  • Python 3.7+

Installation

pip install kuromon
# or if you want to use Pydantic along with kuromon
pip install kuromon[pydantic]

Usage

from kuromon import to_table

dict_data = [
    {"id": 1, "name": "foo", "tags": None},
    {"id": 2, "name": "bar", "tags": ["a"]},
]
print(to_table(dict_data))
# |    |   id | name   | tags   |
# |----|------|--------|--------|
# |  0 |    1 | foo    |        |
# |  1 |    2 | bar    | ['a']  |

# Disable indexing by setting index=False
print(to_table(dict_data, index=False))
# |   id | name   | tags   |
# |------|--------|--------|
# |    1 | foo    |        |
# |    2 | bar    | ['a']  |

# Change the table format via tablefmt
# NOTE: You can use the following tabulate formats
#       https://github.com/astanin/python-tabulate#table-format
print(to_table(dict_data, tablefmt="plain"))
# 0     1  foo
# 1     2  bar     ['a']

The above example uses a list of dict objects. You can also use a list of dataclass or Pydantic objects.

from dataclasses import dataclass
from typing import List, Optional

from dacite import from_dict
from pydantic import BaseModel

from kuromon import to_table


class TestModel(BaseModel):
    id: int
    name: str
    tags: Optional[List[str]]


@dataclass
class TestDataClass:
    id: int
    name: str
    tags: Optional[List[str]]


dict_data = [
    {"id": 1, "name": "foo", "tags": None},
    {"id": 2, "name": "bar", "tags": ["a"]},
]
pydantic_data = [TestModel.parse_obj(obj) for obj in dict_data]
dataclass_data = [from_dict(data_class=TestDataClass, data=obj) for obj in dict_data]

print(to_table(pydantic_data))
print(to_table(dataclass_data))

Metadata

Release files for kuromon 0.2.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 kuromon 0.2.0
File Size Uploaded
kuromon-0.2.0.tar.gz 3.8 kB Details

Built distribution (wheel)

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

Total release size: 7.7 kB

Release files / kuromon-0.2.0.tar.gz

Download URL kuromon-0.2.0.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
502f63042acb51e004f06abc07c46b6bd5ee2c113940a4d77eb95b7d467c23a2
BLAKE2b-256 checksum
How to use checksums
3b68a40e9dbeee3ab0b28ec5e24c9b2179224d7aabdf21636f33cd619a33b8d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.7.6 Darwin/21.5.0

Release files / kuromon-0.2.0-py3-none-any.whl

Download URL kuromon-0.2.0-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4956c7dc85d665021f531dc70b35f90ebed61f0b8f123308943c9f1447e2650b
BLAKE2b-256 checksum
How to use checksums
f2eab8f495a3e238b4569f6fd75bcb58afb02650954147757930b3aff8aabd24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.7.6 Darwin/21.5.0

Release history Release notifications | RSS feed

This release

0.2.0 This release

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