Metadata-Version: 2.4
Name: tabling
Version: 2.0.0
Summary: Tabling is a Python library, inspired by HTML and CSS, for creating highly customizable tables in the console.
Author-email: "Haripo Wesley T." <haripowesleyt@proton.me>
Maintainer-email: "Haripo Wesley T." <haripowesleyt@proton.me>
License: MIT License
        
        Copyright (c) 2025 Haripo Wesley T.
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/haripowesleyt/tabling
Project-URL: Issues, https://github.com/haripowesleyt/tabling/issues
Project-URL: Repository, https://github.com/haripowesleyt/tabling
Keywords: table,tabular
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
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: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: printly>=0.4.0
Dynamic: license-file

# Tabling

[![PyPI - Version](https://img.shields.io/pypi/v/tabling)](https://pypi.org/project/tabling/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/tabling)](https://pypi.org/project/tabling/)
[![License](https://img.shields.io/pypi/l/tabling)](https://github.com/haripowesleyt/tabling/blob/main/LICENSE)
[![Python Versions](https://img.shields.io/pypi/pyversions/tabling)](https://pypi.org/project/tabling/)

Tabling is a Python library, inspired by HTML and CSS, for creating highly customizable tables in the console.

## Key Features

- Add/remove/swap rows, columns, and cells.
- Find & replace values
- Sort rows or columns by key
- Customize background, font, padding, margin, and borders
- Modify text alignment, direction, spacing, wrapping
- 5+ border styles: single, double, dashed, dotted, solid
- 5+ font styles: bold, italic, strikethrough, underline, overline
- All HTML colors: [140+ names](https://htmlcolorcodes.com/color-names/), all RGB values, all HEX codes
- Import/export from CSV, JSON, HTML, Markdown, Plain text, TSV, XLSX, SQLite
- Design UIs like how HTML tables were once used before CSS Grid and Flexbox

## Installation

```bash
pip install tabling
```

## Quick Start

### 1. Create a Table

```python
from tabling import Table

table = Table(colspacing=1, rowspacing=0)
```

### 2. Add Data

```python
table.add_row(("Name", "Age", "Sex"))
table.add_row(("Wesley", 40, "M"))
table.add_row(("Ashley", 22, "F"))
table.add_row(("Lesley", 18, "M"))
table.add_column(("Married", True, False, False))
```

### 3. Print the Table

```python
print(table)
```

![table](https://raw.githubusercontent.com/haripowesleyt/tabling/main/assets/images/table.png)

## Table Operations

| Method                                 | Description                          |
|----------------------------------------|--------------------------------------|
| `add_row(entries)`                     | Add a row                            |
| `add_column(entries)`                  | Add a column                         |
| `insert_row(index, entries)`           | Insert a row at a position           |
| `insert_column(index, entries)`        | Insert a column at a position        |
| `remove_row(index)`                    | Remove a row                         |
| `remove_column(index)`                 | Remove a column                      |
| `swap_rows(index1, index2)`            | Swap two rows                        |
| `swap_columns(index1, index2)`         | Swap two columns                     |
| `sort_rows(key, start=0, reverse=False)`              | Sort rows by column key              |
| `sort_columns(key, start=0, reverse=False)`           | Sort columns by row key              |
| `find(value)`                          | Highlight matching values            |
| `replace(old, new)`                    | Replace values                       |
| `clear()`                              | Remove all rows & columns            |

## Styling & Customization

Each element (table, row, column, cell) supports properties similar to CSS:

| Property   | Attribute      | Type       | Description                  |
|------------|----------------|------------|------------------------------|
| background | color          | str / None | Background color             |
| border     | style          | str / None | Border style                 |
|            | color          | str / None | Border color                 |
| font       | style          | str / None | Font style                   |
|            | color          | str / None | Font color                   |
| margin     | left           | int        | Margin to the left           |
|            | right          | int        | Margin to the right          |
|            | top            | int        | Margin to the top            |
|            | bottom         | int        | Margin to the bottom         |
|            | inline         | tuple      | Margin to the left & right   |
|            | block          | tuple      | Margin to the top & bottom   |
| padding    | left           | int        | Padding to the left          |
|            | right          | int        | Padding to the right         |
|            | top            | int        | Padding to the top           |
|            | bottom         | int        | Padding to the bottom        |
|            | inline         | tuple      | Padding to the left & right  |
|            | block          | tuple      | Padding to the top & bottom  |
| text       | justify        | str        | Horizontal alignment         |
|            | align          | str        | Vertical alignment           |
|            | wrap           | bool       | Whether to wrap              |
|            | visible        | bool       | Whether to show              |
|            | reverse        | bool       | Whether to reverse direction |
|            | letter_spacing | int        | Spaces between letters       |
|            | word_spacing   | int        | Spaces between words         |

\
**General Syntax:** `element.property.attribute = value`

### Example

**Tip:** A table behaves like a list of rows, and a row behaves like a list of cells—both support indexing, slicing, and iteration.

```python
table.border.style = "single"
table[0].font.style = "bold"
for row in table[1:]:
    row.border.top.style = "single"
    row[1].text.justify = "center"
    row[2].text.justify = "center"
```

![customized-table](https://raw.githubusercontent.com/haripowesleyt/tabling/main/assets/images/customized-table.png)

> Explore [Tabling Templates](https://github.com/haripowesleyt/tabling-templates) for ready-made table styles.

## File I/O

Tabling supports multiple file formats via the `tabling.io` module.

### Supported Formats

- CSV, TSV, JSON, HTML, Markdown, Plain text, XLSX, SQLite

### Export Example

```python
from tabling import Table
from tabling.io import csv, tsv, json, html, md, txt, xlsx, sqlite

table = Table(colspacing=1, rowspacing=0)
# Add Data & customize...

csv.dump(table, "table.csv")
tsv.dump(table, "table.tsv")
json.dump(table, "table.json")
html.dump(table, "table.html")
md.dump(table, "table.md")
txt.dump(table, "table.txt")
xlsx.dump(table, "table.xlsx")
sqlite.dump(table, "table.db", "title")
```

### Import Example

```python
from tabling import Table
from tabling.io import csv, tsv, json, html, md, xlsx, sqlite

table = Table(colspacing=1, rowspacing=0)

csv.load(table, "table.csv")
tsv.load(table, "table.tsv")
json.load(table, "table.json")
html.load(table, "table.html")
md.load(table, "table.md")
xlsx.load(table, "table.xlsx")
sqlite.load(table, "table.db", "title")
```

## Contributing

Contributions, suggestions, and issues are welcome! See [CONTRIBUTING.md](https://github.com/haripowesleyt/tabling/blob/main/CONTRIBUTING.md).

## License

This project is licensed under the **MIT License**. See the [LICENSE](https://github.com/haripowesleyt/tabling/blob/main/LICENSE) for full details.
