Skip to content

An intuitive and type-safe Python library for converting lists to fancy ASCII tables for displaying in the terminal or code-blocks

License

Notifications You must be signed in to change notification settings

DenverCoder1/table2ascii

Repository files navigation

table2ascii

build version license Discord

Module for converting 2D Python lists to a fancy ASCII/Unicode tables

📥 Installation

pip install table2ascii

🧑‍💻 Usage

Convert Python lists to ASCII tables

from table2ascii import table2ascii

output = table2ascii(
    header=["#", "G", "H", "R", "S"],
    body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]],
    footer=["SUM", "130", "140", "135", "130"],
)

print(output)

"""
╔═════════════════════════════╗
║  #     G     H     R     S  ║
╟─────────────────────────────╢
║  1    30    40    35    30  ║
║  2    30    40    35    30  ║
╟─────────────────────────────╢
║ SUM   130   140   135   130 ║
╚═════════════════════════════╝
"""
from table2ascii import table2ascii

output = table2ascii(
    body=[["Assignment", "30", "40", "35", "30"], ["Bonus", "10", "20", "5", "10"]],
    first_col_heading=True,
)

print(output)

"""
╔════════════╦═══════════════════╗
║ Assignment ║ 30   40   35   30 ║
║    Bonus   ║ 10   20    5   10 ║
╚════════════╩═══════════════════╝
"""

⚙️ Options

Soon table2ascii will support more options for customization.

Option Type Default Description
first_col_heading bool False Whether to add a heading column seperator after the first column
last_col_heading bool False Whether to add a heading column seperator before the last column

👨‍🎨 Use cases

Discord messages and embeds

  • Display tables nicely inside markdown codeblocks on Discord
  • Useful for making Discord bots with Discord.py

image

Terminal outputs

  • Tables display nicely whenever monospace fonts are fully supported
  • Tables make terminal outputs look more professional

image

🧰 Development

To run tests (pytest)

python setup.py test

To lint (flake8):

python setup.py lint

About

An intuitive and type-safe Python library for converting lists to fancy ASCII tables for displaying in the terminal or code-blocks

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors 8

Languages