Skip to main content

A simple package to easily create a table in console.

Project description

Easy Console Table Package

A package to easily create a console table that can render this :

-------------------------
|   Hello   |   World   |
-------------------------
|     Hello |         1 |
| _________ | _________ |
|     World |         2 |
| _________ | _________ |
|           |         3 |
| _________ | _________ |

How to use it ?

Introduction code

Code to make the introduction table :

from easy_console_table import Table


t = Table()
t.add_column("Hello", ["Hello", "World"])
t.add_column("World", [1, 2, 3])
print(t)

Functionnalities

All methods refer to Table class.

Create a table

You need to create an object of Table that uses **kwargs parameters so you can configure table appearance.

Here's all you can configure : alignment=str, title_separator=str, column_separator=str, line_separator=str.

Base settings are : "alignment": "right", "title_separator": "-", "column_separator": "|", "line_separator": "_"

Even after creating the table you can configure it by using the method config which takes the same arguments.

Add and Delete a column

Add : method add_column that takes as parameters a column's name and a list of values.

Delete : methods Delete_column that takes as parameter a column's name in the table. If a column is delete, it gets removed in the filter.

Set and Get a column

Set : method set_column that takes as parameters a column's name and a list of values.

Get : method get_column that takes as parameter a column's name and return a list of values.

Get table

You can get the whole table implemented using dict of list by using method get_table.

Perfect table

A perfect table is like a perfect graph. It's a table where all the columns have the same lenght.

Use the method get_is_perfect that returns a boolean to know if the table is perfect (True) or not (False).

Filter system

An attribute of Table is a filter. It is a list that contains all the column's names that you don't want to show.

Filter methods

Add : method add_filter makes you add a column's name into the filter. It takes as parameter a column's name that must be in the table.

Remove : method remove_filter makes you remove an element of the filter, remove it by the column's name.

Clear : method clear_filter clear the whole filter.

Sort table

You can sort the whole table by following a column sorting. You can use it with the method sort_table_from_column that takes a column's name as parameter. Table have to be perfect to sort.

Export to CSV

You can export the table to a CSV file by using export_as_csv method that takes as parameter the file path or name. Columns filtered will not be exported.

Mixed example

Code :

from easy_console_table import Table


t = Table(alignment="center", title_separator="#", line_separator="-", column_separator="I")
t.add_column("Hello", ["World", "!", "Hello"])
t.add_column("Sort", [2, 3, 1])
t.add_column("trash", ["Dont", "Work", "As", "It", "Should"])

print(t)
print()

t.add_filter("trash")
print(t)
print()

t.delete_column("trash")
t.sort_table_from_column("Sort")
t.config(alignment="right", title_separator="-", line_separator="_", column_separator="|")
t.add_filter("Sort")
print(t)

It returns :

#####################################
I   Hello   I   Sort    I   trash   I
#####################################
I   World   I     2     I   Dont    I
I --------- I --------- I --------- I
I     !     I     3     I   Work    I
I --------- I --------- I --------- I
I   Hello   I     1     I    As     I
I --------- I --------- I --------- I
I           I           I    It     I
I --------- I --------- I --------- I
I           I           I  Should   I
I --------- I --------- I --------- I

#########################
I   Hello   I   Sort    I
#########################
I   World   I     2     I
I --------- I --------- I
I     !     I     3     I
I --------- I --------- I
I   Hello   I     1     I
I --------- I --------- I
I           I           I
I --------- I --------- I
I           I           I
I --------- I --------- I

-------------
|   Hello   |
-------------
|     Hello |
| _________ |
|     World |
| _________ |
|         ! |
| _________ |

Github link

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easy-console-table-0.0.8.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easy_console_table-0.0.8-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file easy-console-table-0.0.8.tar.gz.

File metadata

  • Download URL: easy-console-table-0.0.8.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.2

File hashes

Hashes for easy-console-table-0.0.8.tar.gz
Algorithm Hash digest
SHA256 a462be927c88109e36ff7417e7705d305e829cd341663dde8dcf99f2c54ede9b
MD5 b522d8850f4f2c6c1763a8a4bb342f1d
BLAKE2b-256 04fdab3e75ec7897aed6ee1a8b6b23b36c44f9ce155cdafb6060c13028966923

See more details on using hashes here.

File details

Details for the file easy_console_table-0.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for easy_console_table-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 acd0231df25ea458fe6aeb88f51d6b0c4343f370a71810d91c83b9e099314eed
MD5 160498df3567349ad28b28b5fb78bffb
BLAKE2b-256 dc222670018aa30b7104e443ff012d8a4d7d87b703799df50e7c92e2e3876ee7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page