Skip to content

Commit

Permalink
readme project.toml and publish.ym files updated
Browse files Browse the repository at this point in the history
  • Loading branch information
CrispenGari committed Feb 10, 2024
1 parent 11194a6 commit ac013ec
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 123 deletions.
194 changes: 142 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ With `tabulato`, you can easily format your data into tables with specified head
- [Key features of tabulato include:](#key-features-of-tabulato-include)
- [Installation](#installation)
- [Example](#example)
- [Arguments](#arguments)
- [Defaults](#defaults)
- [Types](#types)
- [Description](#description)
- [What's missing on this package?](#whats-missing-on-this-package)
- [License](#license)

### Key features of tabulato include:
Expand Down Expand Up @@ -54,72 +51,165 @@ data = [
["Olivia Kim", "S36924", "1993-10-25", "olivia@example.com"],
]

colorful_tabulate(headers=headers, data=data, colorful=True, bold_header=True)
colorful_tabulate(
data=data,
column_widths=[20, 20, 20, 30],
)
```

The above function will result in the following table being created in the terminal.

```shell
+-------------+----------------+------------+---------------------+
| Name | Student Number | DOB | Email Address |
+-------------+----------------+------------+---------------------+
| John Doe | S12345 | 1995-07-15 | john@example.com |
| Alice Smith | S67890 | 1998-03-22 | alice@example.com |
| Bob Johnson | S54321 | 1997-11-10 | bob@example.com |
| Emma Brown | S98765 | 1996-09-18 | emma@example.com |
| Michael Lee | S24680 | 1999-05-30 | michael@example.com |
| Sophia Wang | S13579 | 1994-12-05 | sophia@example.com |
| David Chen | S75310 | 1992-04-08 | david@example.com |
| Olivia Kim | S36924 | 1993-10-25 | olivia@example.com |
+-------------+----------------+------------+---------------------+
+----------------------+----------------------+----------------------+--------------------------------+
| name | student number | dob | email |
+----------------------+----------------------+----------------------+--------------------------------+
| John Doe | S12345 | 1995-07-15 | john@example.com |
| Alice Smith | S67890 | 1998-03-22 | alice@example.com |
| Bob Johnson | S54321 | 1997-11-10 | bob@example.com |
| Emma Brown | S98765 | 1996-09-18 | emma@example.com |
| Michael Lee | S24680 | 1999-05-30 | michael@example.com |
| Sophia Wang | S13579 | 1994-12-05 | sophia@example.com |
| David Chen | S75310 | 1992-04-08 | david@example.com |
| Olivia Kim | S36924 | 1993-10-25 | olivia@example.com |
+----------------------+----------------------+----------------------+--------------------------------+
```

The colorful table will look as follows:

<p align='center'><img src='/images/demo.jpg' alt='demo' width="400"/></p>
<p align='center'><img src='/images/0.jpg' alt='demo' width="400"/></p>

The `colorful_tabulate` is a useful function for visually enhancing tabulated data in terminal output by applying colors and styling.
However you can style the rows of the table using the `TableRowStyle` class by specifying the options as follows:

#### Arguments

| Argument | Type | Default | Description |
| ------------------ | --------------- | ---------- | ----------------------------------------------------------------- |
| `headers` | `list[str]` | | A list of strings representing the headers of the table. |
| `data` | `list[list]` | | A list of lists representing the data rows of the table. |
| `required_columns` | `list[str]` | | A list of strings representing the required columns in the table. |
| `colorful` | `bool` | `True` | A boolean indicating whether to colorize the output. |
| `bold_header` | `bool` | `True` | A boolean indicating whether to make the header bold. |
| `header_color` | `COLOR_LITERAL` | `"BLUE"` | The color of the header. |
| `even_row_color` | `COLOR_LITERAL` | `"GREEN"` | The color of even-numbered rows. |
| `odd_row_color` | `COLOR_LITERAL` | `"YELLOW"` | The color of odd-numbered rows. |
```py
colorful_tabulate(
data=data,
column_widths=[20, 20, 20, 30],
header_style=TableRowStyle(
bold=True,
italic=False,
color="BLUE",
background="BG_BLUE",
),
even_row_style=TableRowStyle(
bold=False,
italic=False,
color="GREEN",
underline=True,
),
odd_row_style=TableRowStyle(
bold=False,
italic=False,
color="YELLOW",
strikethrough=True,
),
)
```

#### Defaults
Output:

- `colorful`: `True`
- `bold_header`: `True`
- `header_color`: `"BLUE"`
- `even_row_color`: `"GREEN"`
- `odd_row_color`: `"YELLOW"`
<p align='center'><img src='/images/1.jpg' alt='demo' width="400"/></p>

#### Types
The table data can also be a list of python dictionaries. Here is an example of using a list of python dictionaries to generate a table.

- `list[str]`: List of strings
- `list[list]`: List of lists
- `bool`: Boolean
- `COLOR_LITERAL`: String representing color (e.g., `"BLUE"`, `"GREEN"`, `"YELLOW"`)
```py

#### Description
data = [
{
"name": "John Doe",
"student number": "S12345",
"dob": "1995-07-15",
"email": "john@example.com",
},
{
"name": "Alice Smith",
"student number": "S67890",
"dob": "1998-03-22",
"email": "alice@example.com",
},
{
"name": "Bob Johnson",
"student number": "S54321",
"dob": "1997-11-10",
"email": "bob@example.com",
},
{
"name": "Emma Brown",
"student number": "S98765",
"dob": "1996-09-18",
"email": "emma@example.com",
},
{
"name": "Michael Lee",
"student number": "S24680",
"dob": "1999-05-30",
"email": "michael@example.com",
},
{
"name": "Sophia Wang",
"student number": "S13579",
"dob": "1994-12-05",
"email": "sophia@example.com",
},
{
"name": "David Chen",
"student number": "S75310",
"dob": "1992-04-08",
"email": "david@example.com",
},
{
"name": "Olivia Kim",
"student number": "S36924",
"dob": "1993-10-25",
"email": "olivia@example.com",
},
]

The `colorful_tabulate` function generates a tabulated representation of data with customizable colors and formatting options. It takes the following arguments:
colorful_tabulate(
data=data,
column_widths=[20, 20, 20, 30],
)
```

- `headers`: A list of strings representing the headers of the table.
- `data`: A list of lists representing the data rows of the table.
- `required_columns`: A list of strings representing the required columns in the table.
- `colorful` (optional, default=`True`): A boolean indicating whether to colorize the output.
- `bold_header` (optional, default=`True`): A boolean indicating whether to make the header bold.
- `header_color` (optional, default=`"BLUE"`): The color of the header.
- `even_row_color` (optional, default=`"GREEN"`): The color of even-numbered rows.
- `odd_row_color` (optional, default=`"YELLOW"`): The color of odd-numbered rows.
The `colorful_tabulate` is a useful function for visually enhancing tabulated data in terminal output by applying colors and styling. The following are the parameters that this function takes.

| Parameter | Description | Type | Default | Required |
| ---------------- | -------------------------------------- | --------------- | -------------------------------------------------------------------------- | -------- |
| `data` | The list of data to be displayed. | `list` | - | `Yes` |
| `headers` | The list of column headers. | `list` | `None` | `No` |
| `colorful` | Whether to display the table in color. | `bool` | `True` | `No` |
| `bold_header` | Whether to display the header in bold. | `bool` | `True` | `No` |
| `header_style` | Style for the header row. | `TableRowStyle` | `TableRowStyle(bold=True, italic=False, color="BLUE", background=None)` | `No` |
| `even_row_style` | Style for even-numbered rows. | `TableRowStyle` | `TableRowStyle(bold=False, italic=False, color="GREEN", background=None)` | `No` |
| `odd_row_style` | Style for odd-numbered rows. | `TableRowStyle` | `TableRowStyle(bold=False, italic=False, color="YELLOW", background=None)` | `No` |
| `column_widths` | List of column widths. | `list` | `[]` | `No` |

The following are the color literals that can be passed to the `color` abd `background` respectively.

| Color | Description |
| ---------- | ----------- |
| `"BLACK"` | Black |
| `"RED"` | Red |
| `"GREEN"` | Green |
| `"YELLOW"` | Yellow |
| `"BLUE"` | Blue |
| `"PURPLE"` | Purple |
| `"CYAN"` | Cyan |
| `"WHITE"` | White |

| Background | Description |
| ------------- | ----------------- |
| `"BG_BLACK"` | Black background |
| `"BG_RED"` | Red background |
| `"BG_GREEN"` | Green background |
| `"BG_BLUE"` | Blue background |
| `"BG_PURPLE"` | Purple background |
| `"BG_CYAN"` | Cyan background |
| `"BG_WHITE"` | White background |
| `"BG_YELLOW"` | Yellow background |

### What's missing on this package?

This package lacks `wrapping` of text for long lines. This `version` only support small tables. Long column data might not end up displayed well, however with small column data like this package is the best.

### License

Expand Down
85 changes: 82 additions & 3 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from tabulato import colorful_tabulate

from tabulato import colorful_tabulate, TableRowStyle

headers = ["Name", "Student Number", "DOB", "Email Address"]

Expand All @@ -15,4 +14,84 @@
]


colorful_tabulate(headers=headers, data=data, colorful=True, bold_header=True)
data = [
{
"name": "John Doe",
"student number": "S12345",
"dob": "1995-07-15",
"email": "john@example.com",
},
{
"name": "Alice Smith",
"student number": "S67890",
"dob": "1998-03-22",
"email": "alice@example.com",
},
{
"name": "Bob Johnson",
"student number": "S54321",
"dob": "1997-11-10",
"email": "bob@example.com",
},
{
"name": "Emma Brown",
"student number": "S98765",
"dob": "1996-09-18",
"email": "emma@example.com",
},
{
"name": "Michael Lee",
"student number": "S24680",
"dob": "1999-05-30",
"email": "michael@example.com",
},
{
"name": "Sophia Wang",
"student number": "S13579",
"dob": "1994-12-05",
"email": "sophia@example.com",
},
{
"name": "David Chen",
"student number": "S75310",
"dob": "1992-04-08",
"email": "david@example.com",
},
{
"name": "Olivia Kim",
"student number": "S36924",
"dob": "1993-10-25",
"email": "olivia@example.com",
},
]

print(data)

colorful_tabulate(
data=data,
column_widths=[20, 20, 20, 30],
)


colorful_tabulate(
data=data,
column_widths=[20, 20, 20, 30],
header_style=TableRowStyle(
bold=True,
italic=False,
color="BLUE",
background="BG_BLUE",
),
even_row_style=TableRowStyle(
bold=False,
italic=False,
color="GREEN",
underline=True,
),
odd_row_style=TableRowStyle(
bold=False,
italic=False,
color="YELLOW",
strikethrough=True,
),
)
Binary file added images/0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/demo.jpg
Binary file not shown.
47 changes: 47 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "tabulato"
version = "0.0.1"
authors = [
{name = "Crispen Gari", email = "crispengari@gmail.com"},
]
description = "This is a Python package that provides functionality for generating tabulated representations of data with customizable colors and formatting options. It offers a user-friendly interface for creating visually appealing tables in terminal output."
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.9"
keywords = ["tabulato", "tables", "pretty-table", "console", "styling", "text-formatting", "CLI", "ANSI", "print", "text-decoration", 'csv', 'tabulate-data' ]
classifiers = [
'Development Status :: 6 - Mature',
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.9",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Terminals",
"Topic :: Utilities",
'Programming Language :: Python',
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.10",
"Operating System :: Unix",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
'Natural Language :: English'
]

[project.urls]
homepage = "https://github.com/CrispenGari/tabulato"
repository = "https://github.com/CrispenGari/tabulato"
documentation = "https://github.com/CrispenGari/tabulato/blob/main/README.md"
changelog = "https://github.com/CrispenGari/tabulato/blob/main/CHANGELOG.md"
issues = "https://github.com/CrispenGari/tabulato/issues"


[tool.setuptools.packages.find]
where = ["."]
include = ["tabulato*"]
exclude = ["tabulato.tests*", 'images', 'tests*', 'tabulato/tests']
namespaces = false

Empty file removed setup.py
Empty file.
4 changes: 2 additions & 2 deletions tabulato/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tabulato.table import colorful_tabulate
from tabulato.table import colorful_tabulate, TableRowStyle


__all__ = [colorful_tabulate]
__all__ = [colorful_tabulate, TableRowStyle]
Loading

0 comments on commit ac013ec

Please sign in to comment.