Coder Social home page Coder Social logo

crispengari / tabulato Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 425 KB

🥶🥶👩‍💻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.

Home Page: https://tabulato.readthedocs.io/en/latest/

License: MIT License

Python 100.00%
csv pretty-print pretty-table python tables

tabulato's Introduction

tabulato

tabulato 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.

With tabulato, you can easily format your data into tables with specified headers, apply different colors to headers and rows, and customize the appearance of your tabulated data. Whether you're working on command-line applications, data analysis scripts, or any other project that requires presenting data in a tabular format, tabulato can help streamline the process and enhance the visual presentation of your data.

Table of Contents

Key features of tabulato include:

  • Generating tables with customizable colors for headers, even rows, and odd rows.
  • Specifying required columns to ensure important data is always displayed.
  • Option to make headers bold for emphasis.
  • User-friendly API for straightforward integration into your Python projects.

tabulato simplifies the task of formatting and presenting tabular data in terminal environments, making it an essential tool for developers and data scientists working with command-line interfaces.

Installation

To install tabulato, you can use pip:

pip install tabulato

Python Version

This package support python version >=3.10

Example

In the following examples shows you how you can use

from tabulato import colorful_tabulate, TableRowStyle

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

data = [
    ["John Doe", "S12345", "1995-07-15", "[email protected]"],
    ["Alice Smith", "S67890", "1998-03-22", "[email protected]"],
    ["Bob Johnson", "S54321", "1997-11-10", "[email protected]"],
    ["Emma Brown", "S98765", "1996-09-18", "[email protected]"],
    ["Michael Lee", "S24680", "1999-05-30", "[email protected]"],
    ["Sophia Wang", "S13579", "1994-12-05", "[email protected]"],
    ["David Chen", "S75310", "1992-04-08", "[email protected]"],
    ["Olivia Kim", "S36924", "1993-10-25", "[email protected]"],
]

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

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

+----------------------+----------------------+----------------------+--------------------------------+
| name                 | student number       | dob                  | email                          |
+----------------------+----------------------+----------------------+--------------------------------+
| John Doe             | S12345               | 1995-07-15           | [email protected]               |
| Alice Smith          | S67890               | 1998-03-22           | [email protected]              |
| Bob Johnson          | S54321               | 1997-11-10           | [email protected]                |
| Emma Brown           | S98765               | 1996-09-18           | [email protected]               |
| Michael Lee          | S24680               | 1999-05-30           | [email protected]            |
| Sophia Wang          | S13579               | 1994-12-05           | [email protected]             |
| David Chen           | S75310               | 1992-04-08           | [email protected]              |
| Olivia Kim           | S36924               | 1993-10-25           | [email protected]             |
+----------------------+----------------------+----------------------+--------------------------------+

The colorful table will look as follows:

demo

However you can style the rows of the table using the TableRowStyle class by specifying the options as follows:

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,
    ),
)

demo

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.

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

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

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.

Docs

You can read the full documentation here.

License

This project is licensed under the MIT License - see the LICENSE file for details.

tabulato's People

Contributors

crispengari avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.