monotable


Namemonotable JSON
Version 3.2.0 PyPI version JSON
download
home_pagehttps://monotable.readthedocs.io/en/latest/
SummaryASCII table with per column format specs and more.
upload_time2024-09-14 15:49:22
maintainerNone
docs_urlNone
authorMark Taylor
requires_python>=3.7
licenseMIT
keywords ascii table pretty
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # monotable

ASCII table with per column format specs, multi-line content,
formatting directives, column width control.

Dataclass to ASCII table printer.

## default branch status

[![](https://img.shields.io/pypi/l/monotable.svg)](http://www.apache.org/licenses/LICENSE-2.0)
[![](https://img.shields.io/pypi/v/monotable.svg)](https://pypi.python.org/pypi/monotable)
[![](https://img.shields.io/pypi/pyversions/monotable.svg)](https://pypi.python.org/pypi/monotable)

[![CI Test](https://github.com/tmarktaylor/monotable/actions/workflows/ci.yml/badge.svg)](https://github.com/tmarktaylor/monotable/actions/workflows/ci.yml)
[![readthedocs](https://readthedocs.org/projects/monotable/badge/?version=latest)](https://monotable.readthedocs.io/en/latest/?badge=latest)
[![codecov](https://codecov.io/gh/tmarktaylor/monotable/branch/master/graph/badge.svg?token=qanSaWfGAQ)](https://codecov.io/gh/tmarktaylor/monotable)

[Docs](https://monotable.readthedocs.io/en/latest/) |
[Repos](https://github.com/tmarktaylor/monotable) |
[Codecov](https://codecov.io/gh/tmarktaylor/monotable?branch=master) |
[License](https://github.com/tmarktaylor/monotable/blob/master/LICENSE)

## Sample usage

```python
from monotable import mono

headings = ["purchased\nparrot\nheart rate", "life\nstate"]

# > is needed to right align None cell since it auto-aligns to left.
# monotable uses empty string to format the second column.
formats = [">(none=rest).0f"]
cells = [
    [0, "demised"],
    [0.0, "passed on"],
    [None, "is no more"],
    [-1],
    [0, "ceased to be"],
]

print(
    mono(
        headings,
        formats,
        cells,
        title="Complaint\n(registered)",
        # top guideline is equals, heading is period, bottom is omitted.
        guideline_chars="=. ",
    )
)
```

sample output:

```expected-output
       Complaint
      (registered)
========================
 purchased
    parrot  life
heart rate  state
........................
         0  demised
         0  passed on
      rest  is no more
        -1
         0  ceased to be
```

## Dataclass to ASCII Table printer

```python
from dataclasses import dataclass, field
from enum import auto, Enum
from monotable import dataclass_print
from monotable import dataclass_format
from monotable import stow
```

### Print a dataclass instance

Print a dataclass as an ASCII table. The field names are left
justified in the left column. The values are right justified
in the right column.

```python
@dataclass
class CurrentConditions:
    temperature: float
    humidity: float
    heat_index: int

weather_data = CurrentConditions(80.0, 0.71, 83)
dataclass_print(weather_data)
```

```expected-output
CurrentConditions
-----------------
temperature  80.0
humidity     0.71
heat_index     83
-----------------
```

### Title

The table title defaults to the class name. The string passed
to the "title" keyword is prepended to the class name.

```python
dataclass_print(weather_data, title="Airport")
```

```expected-output
Airport : CurrentConditions
-----------------
temperature  80.0
humidity     0.71
heat_index     83
-----------------
```

### Format and print later

Call dataclass_format() to print or log later.

```python
text = dataclass_format(weather_data, title="Airport")
print(text)
```

```expected-output
Airport : CurrentConditions
-----------------
temperature  80.0
humidity     0.71
heat_index     83
-----------------
```

### Add a format spec to a dataclass field

Specify formatting for a data class field as shown for
the field() call in place of the default value for the
humidity field below.

The function stow() assigns the dict {"spec": ".0%"} to
the field's metadata dict as the value for the key
"monotable".
The code internally applies this f-string: f"{value:{spec}}"
to format the value.

```python
@dataclass
class SpecCurrentConditions:
    temperature: float
    humidity: float = field(metadata=stow(spec=".0%"))
    heat_index: int

weather_data = SpecCurrentConditions(80.0, 0.71, 83)
dataclass_print(weather_data)
```

```expected-output
SpecCurrentConditions
-----------------
temperature  80.0
humidity      71%
heat_index     83
-----------------
```

### Add a format function to a dataclass field

Specify a format function to do the formatting for a field.

Set the 'spec' key to a callable.
The function takes the field value as the parameter and returns a string.
The string is printed in the table. Note that just the enumeration
name "E" is printed instead of "Direction.E".

```python
class Direction(Enum):
    N = auto()
    E = auto()
    S = auto()
    W = auto()


@dataclass
class Wind:
    speed: int
    direction: Direction = field(metadata=stow(spec=lambda x: x.name))

wind_data = Wind(speed=11,direction=Direction.E)
dataclass_print(wind_data)
```

```expected-output
     Wind
-------------
speed      11
direction   E
-------------
```

### Add text to embellish a field name

Set the 'help' key to add text immediately after the field name.
This is printed in the table left column:
- dataclass field name
- 2 spaces
- 'help' key value.

```python
@dataclass
class MoreConditions:
    visibility: float = field(metadata=stow(help="(mi)",spec=".2f"))
    dewpoint: int = field(metadata=stow(help="(degF)"))

more_data = MoreConditions(visibility=10.00,dewpoint=71)
dataclass_print(more_data)
```

```expected-output
     MoreConditions
-----------------------
visibility  (mi)  10.00
dewpoint  (degF)     71
-----------------------
```

### When a dataclass field value is also dataclass

An additional ASCII table is printed for each nested dataclass.
The table is below and indented two spaces for each level of nesting.

```python
@dataclass
class MoreCurrentConditions:
    temperature: float
    humidity: float
    heat_index: int
    wind: Wind = field(metadata=stow(help="(2pm)"))

more_weather_data = MoreCurrentConditions(
    80.0, 0.71, 83, Wind(11, Direction.E)
    )
dataclass_print(more_weather_data)
```

The class name is printed in place of the value. The value of
the wind field is printed in a second table below the first
and indented two spaces.

```expected-output
MoreCurrentConditions
-----------------
temperature  80.0
humidity     0.71
heat_index     83
wind  (2pm)  Wind
-----------------

  MoreCurrentConditions.wind  (2pm) : Wind
  -------------
  speed      11
  direction   E
  -------------
```

#### Omit printing a nested dataclass

To prevent levels of nested dataclasses from printing pass
keyword parameter max_depth. 1 means just print the top
level of dataclass. Note that only the classname of
the wind field value is printed.

```python
dataclass_print(more_weather_data, max_depth=1)
```

```expected-output
MoreCurrentConditions
-----------------
temperature  80.0
humidity     0.71
heat_index     83
wind  (2pm)  Wind
-----------------
```


#### Print a bordered ASCII table

dataclass_print() passes extra keyword arguments to monotable.mono().
See monotable.mono()'s documentation. Some examples are below.

```python
dataclass_print(more_weather_data, max_depth=1, bordered=True)
```

```expected-output
MoreCurrentConditions
+-------------+------+
| temperature | 80.0 |
+-------------+------+
| humidity    | 0.71 |
+-------------+------+
| heat_index  |   83 |
+-------------+------+
| wind  (2pm) | Wind |
+-------------+------+
```

#### Print ASCII table with indent

```python
dataclass_print(more_weather_data, max_depth=1, indent="....")
```

```expected-output
....MoreCurrentConditions
....-----------------
....temperature  80.0
....humidity     0.71
....heat_index     83
....wind  (2pm)  Wind
....-----------------
```

#### Change the column alignment

```python
dataclass_print(more_weather_data, max_depth=1, formats=(">", "<"))
```

```expected-output
MoreCurrentConditions
-----------------
temperature  80.0
   humidity  0.71
 heat_index  83
wind  (2pm)  Wind
-----------------
```

#### Print a nested dataclass that has a callable spec

For a dataclass field value, set the monotable field metadata
"spec" key to a function so that the value is printed in the top
level table rather than below as a separate table.

Note- This example is coded in Python REPL style so it can be tested
by the PYPI project phmutest using --replmode.

```python
>>> from dataclasses import dataclass, field
>>> from enum import auto, Enum
>>>
>>> from monotable import dataclass_print
>>> from monotable import stow
>>>
>>> class Direction(Enum):
...     N = auto()
...     E = auto()
...     S = auto()
...     W = auto()
>>>
>>> @dataclass
... class Wind:
...     speed: int
...     direction: Direction = field(metadata=stow(spec=lambda x: x.name))
>>>
>>> @dataclass
... class WindInline:
...     temperature: float
...     humidity: float
...     heat_index: int
...     wind: Wind = field(metadata=stow(spec=str))

>>> wind = Wind(11, Direction.E)
>>> wind_inline = WindInline(80.0, 0.71, 83, wind)
>>> dataclass_print(wind_inline)
                       WindInline
-------------------------------------------------------
temperature                                        80.0
humidity                                           0.71
heat_index                                           83
wind         Wind(speed=11, direction=<Direction.E: 2>)
-------------------------------------------------------
```

#### Left align the title

Note "<" at the start of title= specifies left alignment.
monotable detects alignment from the first character of the title.

```python
>>> dataclass_print(wind_inline, title="<Left Aligned Title")
Left Aligned Title : WindInline
-------------------------------------------------------
temperature                                        80.0
humidity                                           0.71
heat_index                                           83
wind         Wind(speed=11, direction=<Direction.E: 2>)
-------------------------------------------------------
```

#### Recipe to do dataclass_print as a mixin class.

```python
from typing import Any, Tuple

class DCPrint:
    """Mixin class for dataclass to add member function dcprint()."""

    # This should be the same signature as dataclass_print()
    # where dataclass_instance is replaced by self.
    def dcprint(
        self,
        *,
        # note- These 2 keyword args are monotable positional args.
        formats: Tuple[str, str] = ("", ">"),
        title: str = "",  # monotable title prefix
        **monotable_kwargs: Any,  # keyword args passed to monotable.mono().
    ) -> None:

        dataclass_print(
            self,
            formats=formats,
            title=title,
            **monotable_kwargs,
        )
```

Add DCPrint as a base class to the dataclass definition.

```python
@dataclass
class Temperatures(DCPrint):
    high: int
    low: int

temps = Temperatures(high=77, low=60)
temps.dcprint(title="High/Low Temperature")
```

```expected-output
High/Low Temperature : Temperatures
--------
high  77
low   60
--------
```

#### Copy of 2 earlier examples in REPL for testing on Python 3.7

```python
>>> @dataclass
... class MoreConditions:
...     visibility: float = field(metadata=stow(help="(mi)",spec=".2f"))
...     dewpoint: int = field(metadata=stow(help="(degF)"))
>>>
>>> more_data = MoreConditions(visibility=10.00,dewpoint=71)
>>> dataclass_print(more_data)
     MoreConditions
-----------------------
visibility  (mi)  10.00
dewpoint  (degF)     71
-----------------------
>>>
>>> @dataclass
... class MoreCurrentConditions:
...     temperature: float
...     humidity: float
...     heat_index: int
...     wind: Wind = field(metadata=stow(help="(2pm)"))
>>>
>>> more_weather_data = MoreCurrentConditions(
...     80.0, 0.71, 83, Wind(11, Direction.E)
...     )
>>> dataclass_print(more_weather_data)
MoreCurrentConditions
-----------------
temperature  80.0
humidity     0.71
heat_index     83
wind  (2pm)  Wind
-----------------
<BLANKLINE>
  MoreCurrentConditions.wind  (2pm) : Wind
  -------------
  speed      11
  direction   E
  -------------
```


                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding those notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

            

Raw data

            {
    "_id": null,
    "home_page": "https://monotable.readthedocs.io/en/latest/",
    "name": "monotable",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "ascii, table, pretty",
    "author": "Mark Taylor",
    "author_email": "mark66547ta2@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/1f/f1/30e60c602de5f98a1fa3dd2e515dc4d025ee9e410b0106c43a51bb26ca3d/monotable-3.2.0.tar.gz",
    "platform": null,
    "description": "# monotable\n\nASCII table with per column format specs, multi-line content,\nformatting directives, column width control.\n\nDataclass to ASCII table printer.\n\n## default branch status\n\n[![](https://img.shields.io/pypi/l/monotable.svg)](http://www.apache.org/licenses/LICENSE-2.0)\n[![](https://img.shields.io/pypi/v/monotable.svg)](https://pypi.python.org/pypi/monotable)\n[![](https://img.shields.io/pypi/pyversions/monotable.svg)](https://pypi.python.org/pypi/monotable)\n\n[![CI Test](https://github.com/tmarktaylor/monotable/actions/workflows/ci.yml/badge.svg)](https://github.com/tmarktaylor/monotable/actions/workflows/ci.yml)\n[![readthedocs](https://readthedocs.org/projects/monotable/badge/?version=latest)](https://monotable.readthedocs.io/en/latest/?badge=latest)\n[![codecov](https://codecov.io/gh/tmarktaylor/monotable/branch/master/graph/badge.svg?token=qanSaWfGAQ)](https://codecov.io/gh/tmarktaylor/monotable)\n\n[Docs](https://monotable.readthedocs.io/en/latest/) |\n[Repos](https://github.com/tmarktaylor/monotable) |\n[Codecov](https://codecov.io/gh/tmarktaylor/monotable?branch=master) |\n[License](https://github.com/tmarktaylor/monotable/blob/master/LICENSE)\n\n## Sample usage\n\n```python\nfrom monotable import mono\n\nheadings = [\"purchased\\nparrot\\nheart rate\", \"life\\nstate\"]\n\n# > is needed to right align None cell since it auto-aligns to left.\n# monotable uses empty string to format the second column.\nformats = [\">(none=rest).0f\"]\ncells = [\n    [0, \"demised\"],\n    [0.0, \"passed on\"],\n    [None, \"is no more\"],\n    [-1],\n    [0, \"ceased to be\"],\n]\n\nprint(\n    mono(\n        headings,\n        formats,\n        cells,\n        title=\"Complaint\\n(registered)\",\n        # top guideline is equals, heading is period, bottom is omitted.\n        guideline_chars=\"=. \",\n    )\n)\n```\n\nsample output:\n\n```expected-output\n       Complaint\n      (registered)\n========================\n purchased\n    parrot  life\nheart rate  state\n........................\n         0  demised\n         0  passed on\n      rest  is no more\n        -1\n         0  ceased to be\n```\n\n## Dataclass to ASCII Table printer\n\n```python\nfrom dataclasses import dataclass, field\nfrom enum import auto, Enum\nfrom monotable import dataclass_print\nfrom monotable import dataclass_format\nfrom monotable import stow\n```\n\n### Print a dataclass instance\n\nPrint a dataclass as an ASCII table. The field names are left\njustified in the left column. The values are right justified\nin the right column.\n\n```python\n@dataclass\nclass CurrentConditions:\n    temperature: float\n    humidity: float\n    heat_index: int\n\nweather_data = CurrentConditions(80.0, 0.71, 83)\ndataclass_print(weather_data)\n```\n\n```expected-output\nCurrentConditions\n-----------------\ntemperature  80.0\nhumidity     0.71\nheat_index     83\n-----------------\n```\n\n### Title\n\nThe table title defaults to the class name. The string passed\nto the \"title\" keyword is prepended to the class name.\n\n```python\ndataclass_print(weather_data, title=\"Airport\")\n```\n\n```expected-output\nAirport : CurrentConditions\n-----------------\ntemperature  80.0\nhumidity     0.71\nheat_index     83\n-----------------\n```\n\n### Format and print later\n\nCall dataclass_format() to print or log later.\n\n```python\ntext = dataclass_format(weather_data, title=\"Airport\")\nprint(text)\n```\n\n```expected-output\nAirport : CurrentConditions\n-----------------\ntemperature  80.0\nhumidity     0.71\nheat_index     83\n-----------------\n```\n\n### Add a format spec to a dataclass field\n\nSpecify formatting for a data class field as shown for\nthe field() call in place of the default value for the\nhumidity field below.\n\nThe function stow() assigns the dict {\"spec\": \".0%\"} to\nthe field's metadata dict as the value for the key\n\"monotable\".\nThe code internally applies this f-string: f\"{value:{spec}}\"\nto format the value.\n\n```python\n@dataclass\nclass SpecCurrentConditions:\n    temperature: float\n    humidity: float = field(metadata=stow(spec=\".0%\"))\n    heat_index: int\n\nweather_data = SpecCurrentConditions(80.0, 0.71, 83)\ndataclass_print(weather_data)\n```\n\n```expected-output\nSpecCurrentConditions\n-----------------\ntemperature  80.0\nhumidity      71%\nheat_index     83\n-----------------\n```\n\n### Add a format function to a dataclass field\n\nSpecify a format function to do the formatting for a field.\n\nSet the 'spec' key to a callable.\nThe function takes the field value as the parameter and returns a string.\nThe string is printed in the table. Note that just the enumeration\nname \"E\" is printed instead of \"Direction.E\".\n\n```python\nclass Direction(Enum):\n    N = auto()\n    E = auto()\n    S = auto()\n    W = auto()\n\n\n@dataclass\nclass Wind:\n    speed: int\n    direction: Direction = field(metadata=stow(spec=lambda x: x.name))\n\nwind_data = Wind(speed=11,direction=Direction.E)\ndataclass_print(wind_data)\n```\n\n```expected-output\n     Wind\n-------------\nspeed      11\ndirection   E\n-------------\n```\n\n### Add text to embellish a field name\n\nSet the 'help' key to add text immediately after the field name.\nThis is printed in the table left column:\n- dataclass field name\n- 2 spaces\n- 'help' key value.\n\n```python\n@dataclass\nclass MoreConditions:\n    visibility: float = field(metadata=stow(help=\"(mi)\",spec=\".2f\"))\n    dewpoint: int = field(metadata=stow(help=\"(degF)\"))\n\nmore_data = MoreConditions(visibility=10.00,dewpoint=71)\ndataclass_print(more_data)\n```\n\n```expected-output\n     MoreConditions\n-----------------------\nvisibility  (mi)  10.00\ndewpoint  (degF)     71\n-----------------------\n```\n\n### When a dataclass field value is also dataclass\n\nAn additional ASCII table is printed for each nested dataclass.\nThe table is below and indented two spaces for each level of nesting.\n\n```python\n@dataclass\nclass MoreCurrentConditions:\n    temperature: float\n    humidity: float\n    heat_index: int\n    wind: Wind = field(metadata=stow(help=\"(2pm)\"))\n\nmore_weather_data = MoreCurrentConditions(\n    80.0, 0.71, 83, Wind(11, Direction.E)\n    )\ndataclass_print(more_weather_data)\n```\n\nThe class name is printed in place of the value. The value of\nthe wind field is printed in a second table below the first\nand indented two spaces.\n\n```expected-output\nMoreCurrentConditions\n-----------------\ntemperature  80.0\nhumidity     0.71\nheat_index     83\nwind  (2pm)  Wind\n-----------------\n\n  MoreCurrentConditions.wind  (2pm) : Wind\n  -------------\n  speed      11\n  direction   E\n  -------------\n```\n\n#### Omit printing a nested dataclass\n\nTo prevent levels of nested dataclasses from printing pass\nkeyword parameter max_depth. 1 means just print the top\nlevel of dataclass. Note that only the classname of\nthe wind field value is printed.\n\n```python\ndataclass_print(more_weather_data, max_depth=1)\n```\n\n```expected-output\nMoreCurrentConditions\n-----------------\ntemperature  80.0\nhumidity     0.71\nheat_index     83\nwind  (2pm)  Wind\n-----------------\n```\n\n\n#### Print a bordered ASCII table\n\ndataclass_print() passes extra keyword arguments to monotable.mono().\nSee monotable.mono()'s documentation. Some examples are below.\n\n```python\ndataclass_print(more_weather_data, max_depth=1, bordered=True)\n```\n\n```expected-output\nMoreCurrentConditions\n+-------------+------+\n| temperature | 80.0 |\n+-------------+------+\n| humidity    | 0.71 |\n+-------------+------+\n| heat_index  |   83 |\n+-------------+------+\n| wind  (2pm) | Wind |\n+-------------+------+\n```\n\n#### Print ASCII table with indent\n\n```python\ndataclass_print(more_weather_data, max_depth=1, indent=\"....\")\n```\n\n```expected-output\n....MoreCurrentConditions\n....-----------------\n....temperature  80.0\n....humidity     0.71\n....heat_index     83\n....wind  (2pm)  Wind\n....-----------------\n```\n\n#### Change the column alignment\n\n```python\ndataclass_print(more_weather_data, max_depth=1, formats=(\">\", \"<\"))\n```\n\n```expected-output\nMoreCurrentConditions\n-----------------\ntemperature  80.0\n   humidity  0.71\n heat_index  83\nwind  (2pm)  Wind\n-----------------\n```\n\n#### Print a nested dataclass that has a callable spec\n\nFor a dataclass field value, set the monotable field metadata\n\"spec\" key to a function so that the value is printed in the top\nlevel table rather than below as a separate table.\n\nNote- This example is coded in Python REPL style so it can be tested\nby the PYPI project phmutest using --replmode.\n\n```python\n>>> from dataclasses import dataclass, field\n>>> from enum import auto, Enum\n>>>\n>>> from monotable import dataclass_print\n>>> from monotable import stow\n>>>\n>>> class Direction(Enum):\n...     N = auto()\n...     E = auto()\n...     S = auto()\n...     W = auto()\n>>>\n>>> @dataclass\n... class Wind:\n...     speed: int\n...     direction: Direction = field(metadata=stow(spec=lambda x: x.name))\n>>>\n>>> @dataclass\n... class WindInline:\n...     temperature: float\n...     humidity: float\n...     heat_index: int\n...     wind: Wind = field(metadata=stow(spec=str))\n\n>>> wind = Wind(11, Direction.E)\n>>> wind_inline = WindInline(80.0, 0.71, 83, wind)\n>>> dataclass_print(wind_inline)\n                       WindInline\n-------------------------------------------------------\ntemperature                                        80.0\nhumidity                                           0.71\nheat_index                                           83\nwind         Wind(speed=11, direction=<Direction.E: 2>)\n-------------------------------------------------------\n```\n\n#### Left align the title\n\nNote \"<\" at the start of title= specifies left alignment.\nmonotable detects alignment from the first character of the title.\n\n```python\n>>> dataclass_print(wind_inline, title=\"<Left Aligned Title\")\nLeft Aligned Title : WindInline\n-------------------------------------------------------\ntemperature                                        80.0\nhumidity                                           0.71\nheat_index                                           83\nwind         Wind(speed=11, direction=<Direction.E: 2>)\n-------------------------------------------------------\n```\n\n#### Recipe to do dataclass_print as a mixin class.\n\n```python\nfrom typing import Any, Tuple\n\nclass DCPrint:\n    \"\"\"Mixin class for dataclass to add member function dcprint().\"\"\"\n\n    # This should be the same signature as dataclass_print()\n    # where dataclass_instance is replaced by self.\n    def dcprint(\n        self,\n        *,\n        # note- These 2 keyword args are monotable positional args.\n        formats: Tuple[str, str] = (\"\", \">\"),\n        title: str = \"\",  # monotable title prefix\n        **monotable_kwargs: Any,  # keyword args passed to monotable.mono().\n    ) -> None:\n\n        dataclass_print(\n            self,\n            formats=formats,\n            title=title,\n            **monotable_kwargs,\n        )\n```\n\nAdd DCPrint as a base class to the dataclass definition.\n\n```python\n@dataclass\nclass Temperatures(DCPrint):\n    high: int\n    low: int\n\ntemps = Temperatures(high=77, low=60)\ntemps.dcprint(title=\"High/Low Temperature\")\n```\n\n```expected-output\nHigh/Low Temperature : Temperatures\n--------\nhigh  77\nlow   60\n--------\n```\n\n#### Copy of 2 earlier examples in REPL for testing on Python 3.7\n\n```python\n>>> @dataclass\n... class MoreConditions:\n...     visibility: float = field(metadata=stow(help=\"(mi)\",spec=\".2f\"))\n...     dewpoint: int = field(metadata=stow(help=\"(degF)\"))\n>>>\n>>> more_data = MoreConditions(visibility=10.00,dewpoint=71)\n>>> dataclass_print(more_data)\n     MoreConditions\n-----------------------\nvisibility  (mi)  10.00\ndewpoint  (degF)     71\n-----------------------\n>>>\n>>> @dataclass\n... class MoreCurrentConditions:\n...     temperature: float\n...     humidity: float\n...     heat_index: int\n...     wind: Wind = field(metadata=stow(help=\"(2pm)\"))\n>>>\n>>> more_weather_data = MoreCurrentConditions(\n...     80.0, 0.71, 83, Wind(11, Direction.E)\n...     )\n>>> dataclass_print(more_weather_data)\nMoreCurrentConditions\n-----------------\ntemperature  80.0\nhumidity     0.71\nheat_index     83\nwind  (2pm)  Wind\n-----------------\n<BLANKLINE>\n  MoreCurrentConditions.wind  (2pm) : Wind\n  -------------\n  speed      11\n  direction   E\n  -------------\n```\n\n\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "ASCII table with per column format specs and more.",
    "version": "3.2.0",
    "project_urls": {
        "Bug Reports": "https://github.com/tmarktaylor/monotable/issues",
        "Homepage": "https://monotable.readthedocs.io/en/latest/",
        "Source": "https://github.com/tmarktaylor/monotable/"
    },
    "split_keywords": [
        "ascii",
        " table",
        " pretty"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3b3030e4ce8130ea9645f8f56dff676ce2aeb68d9d0b5f556904145d3ea18a0e",
                "md5": "fb70acdcd2274e07d7885b57d054ac5c",
                "sha256": "5b870a8bb02ca3717f554535f8ce5a0a62b2ad99adc237a363144d5874251bde"
            },
            "downloads": -1,
            "filename": "monotable-3.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fb70acdcd2274e07d7885b57d054ac5c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 46450,
            "upload_time": "2024-09-14T15:49:20",
            "upload_time_iso_8601": "2024-09-14T15:49:20.528913Z",
            "url": "https://files.pythonhosted.org/packages/3b/30/30e4ce8130ea9645f8f56dff676ce2aeb68d9d0b5f556904145d3ea18a0e/monotable-3.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1ff130e60c602de5f98a1fa3dd2e515dc4d025ee9e410b0106c43a51bb26ca3d",
                "md5": "5e35e4b8476bf5e94bf47f8c663a723e",
                "sha256": "3e215bdac7d0849d7e4f79c67790009f1ce63814a06403bef229c347cfbe3bc6"
            },
            "downloads": -1,
            "filename": "monotable-3.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "5e35e4b8476bf5e94bf47f8c663a723e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 91356,
            "upload_time": "2024-09-14T15:49:22",
            "upload_time_iso_8601": "2024-09-14T15:49:22.663556Z",
            "url": "https://files.pythonhosted.org/packages/1f/f1/30e60c602de5f98a1fa3dd2e515dc4d025ee9e410b0106c43a51bb26ca3d/monotable-3.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-14 15:49:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tmarktaylor",
    "github_project": "monotable",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "monotable"
}
        
Elapsed time: 0.32632s