pretty-tabulate 2.37.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pretty_tabulate-2.37.1/LICENSE +21 -0
- pretty_tabulate-2.37.1/PKG-INFO +73 -0
- pretty_tabulate-2.37.1/README.md +54 -0
- pretty_tabulate-2.37.1/pretty_tabulate/__init__.py +14 -0
- pretty_tabulate-2.37.1/pretty_tabulate/colors.py +36 -0
- pretty_tabulate-2.37.1/pretty_tabulate/formatter.py +106 -0
- pretty_tabulate-2.37.1/pretty_tabulate.egg-info/PKG-INFO +73 -0
- pretty_tabulate-2.37.1/pretty_tabulate.egg-info/SOURCES.txt +11 -0
- pretty_tabulate-2.37.1/pretty_tabulate.egg-info/dependency_links.txt +1 -0
- pretty_tabulate-2.37.1/pretty_tabulate.egg-info/requires.txt +1 -0
- pretty_tabulate-2.37.1/pretty_tabulate.egg-info/top_level.txt +1 -0
- pretty_tabulate-2.37.1/pyproject.toml +27 -0
- pretty_tabulate-2.37.1/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Liam Taylor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pretty-tabulate
|
|
3
|
+
Version: 2.37.1
|
|
4
|
+
Summary: Lightweight table formatting with color support for terminal output
|
|
5
|
+
Author: Liam Taylor
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: table,formatting,terminal,color,cli
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
13
|
+
Classifier: Topic :: Utilities
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: color-list>=1.0.2
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# Pretty Tabulate
|
|
21
|
+
|
|
22
|
+
A lightweight Python library for formatting data as beautiful, colored tables in the terminal.
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- Simple API for creating formatted tables
|
|
27
|
+
- ANSI color support with automatic terminal detection
|
|
28
|
+
- Configurable column alignment, padding, and borders
|
|
29
|
+
- Works with lists of dicts, lists of lists, or pandas DataFrames
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install pretty-tabulate
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from pretty_tabulate import PrettyTable, Color
|
|
41
|
+
|
|
42
|
+
# Create a table from data
|
|
43
|
+
data = [
|
|
44
|
+
{"name": "Alice", "score": 95, "grade": "A"},
|
|
45
|
+
{"name": "Bob", "score": 87, "grade": "B+"},
|
|
46
|
+
{"name": "Charlie", "score": 72, "grade": "C"},
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
table = PrettyTable(data)
|
|
50
|
+
print(table.render(color=Color.GREEN))
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## API Reference
|
|
54
|
+
|
|
55
|
+
### `PrettyTable(data, headers=None)`
|
|
56
|
+
|
|
57
|
+
Create a table from data (list of dicts or list of lists).
|
|
58
|
+
|
|
59
|
+
### `table.render(color=None, border=True, padding=1)`
|
|
60
|
+
|
|
61
|
+
Render the table as a formatted string.
|
|
62
|
+
|
|
63
|
+
### `format_table(data, headers=None, color=None)`
|
|
64
|
+
|
|
65
|
+
One-liner convenience function.
|
|
66
|
+
|
|
67
|
+
### `colorize(text, color)`
|
|
68
|
+
|
|
69
|
+
Apply ANSI color to text.
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Pretty Tabulate
|
|
2
|
+
|
|
3
|
+
A lightweight Python library for formatting data as beautiful, colored tables in the terminal.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Simple API for creating formatted tables
|
|
8
|
+
- ANSI color support with automatic terminal detection
|
|
9
|
+
- Configurable column alignment, padding, and borders
|
|
10
|
+
- Works with lists of dicts, lists of lists, or pandas DataFrames
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install pretty-tabulate
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from pretty_tabulate import PrettyTable, Color
|
|
22
|
+
|
|
23
|
+
# Create a table from data
|
|
24
|
+
data = [
|
|
25
|
+
{"name": "Alice", "score": 95, "grade": "A"},
|
|
26
|
+
{"name": "Bob", "score": 87, "grade": "B+"},
|
|
27
|
+
{"name": "Charlie", "score": 72, "grade": "C"},
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
table = PrettyTable(data)
|
|
31
|
+
print(table.render(color=Color.GREEN))
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## API Reference
|
|
35
|
+
|
|
36
|
+
### `PrettyTable(data, headers=None)`
|
|
37
|
+
|
|
38
|
+
Create a table from data (list of dicts or list of lists).
|
|
39
|
+
|
|
40
|
+
### `table.render(color=None, border=True, padding=1)`
|
|
41
|
+
|
|
42
|
+
Render the table as a formatted string.
|
|
43
|
+
|
|
44
|
+
### `format_table(data, headers=None, color=None)`
|
|
45
|
+
|
|
46
|
+
One-liner convenience function.
|
|
47
|
+
|
|
48
|
+
### `colorize(text, color)`
|
|
49
|
+
|
|
50
|
+
Apply ANSI color to text.
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""PrettyTable - Lightweight table formatting with color support for terminal output."""
|
|
2
|
+
|
|
3
|
+
__version__ = "2.37.1"
|
|
4
|
+
__author__ = "Liam Taylor"
|
|
5
|
+
|
|
6
|
+
from .formatter import PrettyTable, format_table
|
|
7
|
+
from .colors import Color, colorize, supports_color
|
|
8
|
+
|
|
9
|
+
# Extend Color class with comprehensive colors from color-list library
|
|
10
|
+
from color_list import get_color_list as _get_color_list
|
|
11
|
+
|
|
12
|
+
for _name, _code in _get_color_list():
|
|
13
|
+
if not hasattr(Color, _name):
|
|
14
|
+
setattr(Color, _name, _code)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Color utilities for terminal output."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Color:
|
|
8
|
+
"""ANSI color constants for terminal output."""
|
|
9
|
+
RESET = "\033[0m"
|
|
10
|
+
RED = "\033[91m"
|
|
11
|
+
GREEN = "\033[92m"
|
|
12
|
+
YELLOW = "\033[93m"
|
|
13
|
+
BLUE = "\033[94m"
|
|
14
|
+
MAGENTA = "\033[95m"
|
|
15
|
+
CYAN = "\033[96m"
|
|
16
|
+
WHITE = "\033[97m"
|
|
17
|
+
BOLD = "\033[1m"
|
|
18
|
+
DIM = "\033[2m"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def supports_color() -> bool:
|
|
22
|
+
"""Check if the terminal supports ANSI colors."""
|
|
23
|
+
if os.environ.get("NO_COLOR"):
|
|
24
|
+
return False
|
|
25
|
+
if os.environ.get("FORCE_COLOR"):
|
|
26
|
+
return True
|
|
27
|
+
if not hasattr(sys.stdout, "isatty"):
|
|
28
|
+
return False
|
|
29
|
+
return sys.stdout.isatty()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def colorize(text: str, color: str) -> str:
|
|
33
|
+
"""Apply ANSI color to text if terminal supports it."""
|
|
34
|
+
if not supports_color():
|
|
35
|
+
return text
|
|
36
|
+
return f"{color}{text}{Color.RESET}"
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Table formatting utilities for terminal display."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from .colors import Color, colorize, supports_color
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PrettyTable:
|
|
9
|
+
"""Format tabular data for terminal display with optional color support."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, data: list[dict[str, Any]] | list[list[Any]], headers: list[str] | None = None):
|
|
12
|
+
if not data:
|
|
13
|
+
self._headers = headers or []
|
|
14
|
+
self._rows = []
|
|
15
|
+
return
|
|
16
|
+
|
|
17
|
+
if isinstance(data[0], dict):
|
|
18
|
+
self._headers = headers or list(data[0].keys())
|
|
19
|
+
self._rows = [[str(row.get(h, "")) for h in self._headers] for row in data]
|
|
20
|
+
else:
|
|
21
|
+
self._headers = headers or [f"Col {i}" for i in range(len(data[0]))]
|
|
22
|
+
self._rows = [[str(cell) for cell in row] for row in data]
|
|
23
|
+
|
|
24
|
+
def render(self, color: str | None = None, border: bool = True, padding: int = 1) -> str:
|
|
25
|
+
"""Render the table as a formatted string.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
color: ANSI color code to apply to headers (e.g. Color.GREEN)
|
|
29
|
+
border: Whether to draw box borders
|
|
30
|
+
padding: Cell padding (spaces on each side)
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
Formatted table string
|
|
34
|
+
"""
|
|
35
|
+
if not self._headers and not self._rows:
|
|
36
|
+
return ""
|
|
37
|
+
|
|
38
|
+
# Calculate column widths
|
|
39
|
+
all_rows = [self._headers] + self._rows
|
|
40
|
+
col_widths = [
|
|
41
|
+
max(len(str(row[i])) for row in all_rows) + padding * 2
|
|
42
|
+
for i in range(len(self._headers))
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
pad = " " * padding
|
|
46
|
+
lines = []
|
|
47
|
+
|
|
48
|
+
if border:
|
|
49
|
+
top = "┌" + "┬".join("─" * w for w in col_widths) + "┐"
|
|
50
|
+
mid = "├" + "┼".join("─" * w for w in col_widths) + "┤"
|
|
51
|
+
bot = "└" + "┴".join("─" * w for w in col_widths) + "┘"
|
|
52
|
+
lines.append(top)
|
|
53
|
+
|
|
54
|
+
# Header row
|
|
55
|
+
header_cells = []
|
|
56
|
+
for i, h in enumerate(self._headers):
|
|
57
|
+
cell = f"{pad}{h:<{col_widths[i] - padding * 2}}{pad}"
|
|
58
|
+
if color:
|
|
59
|
+
cell = colorize(cell, color)
|
|
60
|
+
header_cells.append(cell)
|
|
61
|
+
if border:
|
|
62
|
+
lines.append("│" + "│".join(header_cells) + "│")
|
|
63
|
+
lines.append(mid)
|
|
64
|
+
else:
|
|
65
|
+
lines.append(" ".join(header_cells))
|
|
66
|
+
lines.append("-" * sum(col_widths))
|
|
67
|
+
|
|
68
|
+
# Data rows
|
|
69
|
+
for row in self._rows:
|
|
70
|
+
cells = []
|
|
71
|
+
for i, cell in enumerate(row):
|
|
72
|
+
cells.append(f"{pad}{cell:<{col_widths[i] - padding * 2}}{pad}")
|
|
73
|
+
if border:
|
|
74
|
+
lines.append("│" + "│".join(cells) + "│")
|
|
75
|
+
else:
|
|
76
|
+
lines.append(" ".join(cells))
|
|
77
|
+
|
|
78
|
+
if border:
|
|
79
|
+
lines.append(bot)
|
|
80
|
+
|
|
81
|
+
return "\n".join(lines)
|
|
82
|
+
|
|
83
|
+
def __str__(self) -> str:
|
|
84
|
+
return self.render()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def format_table(
|
|
88
|
+
data: list[dict[str, Any]] | list[list[Any]],
|
|
89
|
+
headers: list[str] | None = None,
|
|
90
|
+
color: str | None = None,
|
|
91
|
+
border: bool = True,
|
|
92
|
+
padding: int = 1,
|
|
93
|
+
) -> str:
|
|
94
|
+
"""One-liner convenience function for formatted table output.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
data: List of dicts or list of lists
|
|
98
|
+
headers: Column headers (auto-detected from dict keys if not provided)
|
|
99
|
+
color: ANSI color for headers
|
|
100
|
+
border: Draw box borders
|
|
101
|
+
padding: Cell padding
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
Formatted table string
|
|
105
|
+
"""
|
|
106
|
+
return PrettyTable(data, headers).render(color=color, border=border, padding=padding)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pretty-tabulate
|
|
3
|
+
Version: 2.37.1
|
|
4
|
+
Summary: Lightweight table formatting with color support for terminal output
|
|
5
|
+
Author: Liam Taylor
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: table,formatting,terminal,color,cli
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
13
|
+
Classifier: Topic :: Utilities
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: color-list>=1.0.2
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# Pretty Tabulate
|
|
21
|
+
|
|
22
|
+
A lightweight Python library for formatting data as beautiful, colored tables in the terminal.
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- Simple API for creating formatted tables
|
|
27
|
+
- ANSI color support with automatic terminal detection
|
|
28
|
+
- Configurable column alignment, padding, and borders
|
|
29
|
+
- Works with lists of dicts, lists of lists, or pandas DataFrames
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install pretty-tabulate
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from pretty_tabulate import PrettyTable, Color
|
|
41
|
+
|
|
42
|
+
# Create a table from data
|
|
43
|
+
data = [
|
|
44
|
+
{"name": "Alice", "score": 95, "grade": "A"},
|
|
45
|
+
{"name": "Bob", "score": 87, "grade": "B+"},
|
|
46
|
+
{"name": "Charlie", "score": 72, "grade": "C"},
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
table = PrettyTable(data)
|
|
50
|
+
print(table.render(color=Color.GREEN))
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## API Reference
|
|
54
|
+
|
|
55
|
+
### `PrettyTable(data, headers=None)`
|
|
56
|
+
|
|
57
|
+
Create a table from data (list of dicts or list of lists).
|
|
58
|
+
|
|
59
|
+
### `table.render(color=None, border=True, padding=1)`
|
|
60
|
+
|
|
61
|
+
Render the table as a formatted string.
|
|
62
|
+
|
|
63
|
+
### `format_table(data, headers=None, color=None)`
|
|
64
|
+
|
|
65
|
+
One-liner convenience function.
|
|
66
|
+
|
|
67
|
+
### `colorize(text, color)`
|
|
68
|
+
|
|
69
|
+
Apply ANSI color to text.
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
pretty_tabulate/__init__.py
|
|
5
|
+
pretty_tabulate/colors.py
|
|
6
|
+
pretty_tabulate/formatter.py
|
|
7
|
+
pretty_tabulate.egg-info/PKG-INFO
|
|
8
|
+
pretty_tabulate.egg-info/SOURCES.txt
|
|
9
|
+
pretty_tabulate.egg-info/dependency_links.txt
|
|
10
|
+
pretty_tabulate.egg-info/requires.txt
|
|
11
|
+
pretty_tabulate.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
color-list>=1.0.2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pretty_tabulate
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pretty-tabulate"
|
|
3
|
+
version = "2.37.1"
|
|
4
|
+
description = "Lightweight table formatting with color support for terminal output"
|
|
5
|
+
requires-python = ">=3.10"
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
license = {text = "MIT"}
|
|
8
|
+
authors = [
|
|
9
|
+
{name = "Liam Taylor"},
|
|
10
|
+
]
|
|
11
|
+
dependencies = ["color-list>=1.0.2"]
|
|
12
|
+
keywords = ["table", "formatting", "terminal", "color", "cli"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
19
|
+
"Topic :: Utilities",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[build-system]
|
|
23
|
+
requires = ["setuptools", "wheel"]
|
|
24
|
+
build-backend = "setuptools.build_meta"
|
|
25
|
+
|
|
26
|
+
[tool.setuptools]
|
|
27
|
+
packages = ["pretty_tabulate"]
|