Skip to main content

A small library to print structured data tables

Project description

basictable

Small library to print structured data in tables

License

MIT

Installation

pip3 install basictable

Data Format

The recordset format is a list of dictionaries where the dictionary keys are the column headings. All the records are required to have the same number of columns and same heading values (keys)

[
    {'Col1':data1, 'Col2': data2, 'Col3':data2, 'Col4':'data4'},
    {'Col1':data1, 'Col2': data2, 'Col3':data2, 'Col4':'data4'},
    {'Col1':data1, 'Col2': data2, 'Col3':data2, 'Col4':'data4'},
    {'Col1':data1, 'Col2': data2, 'Col3':data2, 'Col4':'data4'},
]

Usage

>>> from basictable import print_table
>>> data = []
>>> for i in range(20):
...  data.append({'Col1':1, 'Col2': "test", 'Col3':'test test', 'Col4':'some longer string'})
...
>>> print_table(data)
    Col3               Col4            Col1     Col2
  ---------     ------------------     ----     ----
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
>>> print_table(data, border=True)
|------------------------------------------------------|
|    Col3     |         Col4         |  Col1  |  Col2  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|-------------+----------------------+--------+--------|
|  test test  |  some longer string  |  1     |  test  |
|------------------------------------------------------|
>>> print_table(data, headings_justify='left')
  Col3          Col4                   Col1     Col2
  ---------     ------------------     ----     ----
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
  test test     some longer string     1        test
>>> print_table(data, headings_justify='left', order=('Col4','Col3','Col2','Col1'))
  Col4                   Col3          Col2     Col1
  ------------------     ---------     ----     ----
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
  some longer string     test test     test     1
>>> print_table(data, data_justify='center', order=('Col1',))
  Col1     Col2            Col4              Col3
  ----     ----     ------------------     ---------
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
   1       test     some longer string     test test
>>> print_table(data, data_justify='center', order=('Col1','Col2','Col3'))
  Col1     Col2       Col3               Col4
  ----     ----     ---------     ------------------
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
   1       test     test test     some longer string
>>> print_table(data, data_justify='center', border=True, order=('Col1','Col2','Col3'))
|------------------------------------------------------|
|  Col1  |  Col2  |    Col3     |         Col4         |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|--------+--------+-------------+----------------------|
|   1    |  test  |  test test  |  some longer string  |
|------------------------------------------------------|
>>> print_table(data, data_justify='center', border=True, order=('Col1','Col2','Col3'), padding=8)
|------------------------------------------------------------------------------------------------------|
|        Col1        |        Col2        |          Col3           |               Col4               |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|--------------------+--------------------+-------------------------+----------------------------------|
|         1          |        test        |        test test        |        some longer string        |
|------------------------------------------------------------------------------------------------------|
>>> print_table(data, border=True, records_per_page=3)
|------------------------------------------------------|
|  Col1  |    Col3     |  Col2  |         Col4         |
|--------+-------------+--------+----------------------|
|  1     |  test test  |  test  |  some longer string  |
|--------+-------------+--------+----------------------|
|  1     |  test test  |  test  |  some longer string  |
|--------+-------------+--------+----------------------|
|  1     |  test test  |  test  |  some longer string  |
|--------+-------------+--------+----------------------|
[press any key]
|  1     |  test test  |  test  |  some longer string  |
|--------+-------------+--------+----------------------|
|  1     |  test test  |  test  |  some longer string  |
|--------+-------------+--------+----------------------|
|  1     |  test test  |  test  |  some longer string  |
|--------+-------------+--------+----------------------|
[press any key]
|  1     |  test test  |  test  |  some longer string  |
|--------+-------------+--------+----------------------|
|  1     |  test test  |  test  |  some longer string  |
|--------+-------------+--------+----------------------|
|  1     |  test test  |  test  |  some longer string  |
|--------+-------------+--------+----------------------|
[press any key]
|  1     |  test test  |  test  |  some longer string  |
|------------------------------------------------------|

Project details


Download files

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

Files for basictable, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size basictable-1.0.1-py3-none-any.whl (6.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size basictable-1.0.1.tar.gz (4.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page