Metadata-Version: 2.4
Name: philiprehberger-cli-table
Version: 0.1.10
Summary: Format Python data as aligned terminal tables with no dependencies
Project-URL: Homepage, https://github.com/philiprehberger/py-cli-table#readme
Project-URL: Repository, https://github.com/philiprehberger/py-cli-table
Project-URL: Issues, https://github.com/philiprehberger/py-cli-table/issues
Project-URL: Changelog, https://github.com/philiprehberger/py-cli-table/blob/main/CHANGELOG.md
Author: Philip Rehberger
License-Expression: MIT
License-File: LICENSE
Keywords: cli,format,pretty-print,table,terminal
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# philiprehberger-cli-table

[![Tests](https://github.com/philiprehberger/py-cli-table/actions/workflows/publish.yml/badge.svg)](https://github.com/philiprehberger/py-cli-table/actions/workflows/publish.yml)
[![PyPI version](https://img.shields.io/pypi/v/philiprehberger-cli-table.svg)](https://pypi.org/project/philiprehberger-cli-table/)
[![Last updated](https://img.shields.io/github/last-commit/philiprehberger/py-cli-table)](https://github.com/philiprehberger/py-cli-table/commits/main)

Format Python data as aligned terminal tables with no dependencies.

## Installation

```bash
pip install philiprehberger-cli-table
```

## Usage

### Dict list mode

```python
from philiprehberger_cli_table import table

data = [
    {"name": "Alice", "age": 30, "city": "Berlin"},
    {"name": "Bob", "age": 25, "city": "Vienna"},
    {"name": "Charlie", "age": 35, "city": "Zurich"},
]

table(data)
# name     age  city
# -------  ---  ------
# Alice    30   Berlin
# Bob      25   Vienna
# Charlie  35   Zurich
```

### Headers + rows mode

```python
from philiprehberger_cli_table import table

table(
    headers=["Product", "Price", "Stock"],
    rows=[
        ["Widget", "9.99", "142"],
        ["Gadget", "24.99", "38"],
    ],
)
# Product  Price  Stock
# -------  -----  -----
# Widget   9.99   142
# Gadget   24.99  38
```

### Column alignment

```python
from philiprehberger_cli_table import table

table(
    data=[
        {"item": "Coffee", "qty": 3, "price": "4.50"},
        {"item": "Tea", "qty": 12, "price": "2.00"},
    ],
    align={"qty": "right", "price": "right"},
)
# item    qty  price
# ------  ---  -----
# Coffee    3   4.50
# Tea      12   2.00
```

### Styles

```python
from philiprehberger_cli_table import format_table

# Markdown style
print(format_table(
    headers=["Name", "Score"],
    rows=[["Alice", "95"], ["Bob", "87"]],
    style="markdown",
))
# | Name  | Score |
# | ----- | ----- |
# | Alice | 95    |
# | Bob   | 87    |

# No borders
print(format_table(
    headers=["Name", "Score"],
    rows=[["Alice", "95"], ["Bob", "87"]],
    style="none",
))
# Name   Score
# Alice  95
# Bob    87
```

### Cell truncation

```python
from philiprehberger_cli_table import table

table(
    data=[{"description": "A very long description that goes on and on"}],
    max_width=20,
)
```

## Wide character support

Supports CJK and other wide Unicode characters with correct column alignment.

## API

| Function | Description |
| --- | --- |
| `format_table(headers, rows, *, data, align, max_width, style)` | Returns a formatted table as a string |
| `table(data, headers, rows, **kwargs)` | Prints a formatted table to stdout |

### Parameters

| Parameter | Type | Default | Description |
| --- | --- | --- | --- |
| `headers` | `list[str] \| None` | `None` | Column header names |
| `rows` | `list[list[Any]] \| None` | `None` | List of row value lists |
| `data` | `list[dict[str, Any]] \| None` | `None` | List of dicts (keys become headers) |
| `align` | `dict[str, Align] \| None` | `None` | Per-column alignment: `"left"`, `"right"`, `"center"` |
| `max_width` | `int \| None` | `None` | Truncate cell values to this width |
| `style` | `Style` | `"simple"` | Border style: `"simple"`, `"markdown"`, `"none"` |

## Development

```bash
pip install -e .
python -m pytest tests/ -v
```

## Support

If you find this project useful:

⭐ [Star the repo](https://github.com/philiprehberger/py-cli-table)

🐛 [Report issues](https://github.com/philiprehberger/py-cli-table/issues?q=is%3Aissue+is%3Aopen+label%3Abug)

💡 [Suggest features](https://github.com/philiprehberger/py-cli-table/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)

❤️ [Sponsor development](https://github.com/sponsors/philiprehberger)

🌐 [All Open Source Projects](https://philiprehberger.com/open-source-packages)

💻 [GitHub Profile](https://github.com/philiprehberger)

🔗 [LinkedIn Profile](https://www.linkedin.com/in/philiprehberger)

## License

[MIT](LICENSE)
