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.

Source Distribution

basictable-1.0.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

basictable-1.0.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file basictable-1.0.1.tar.gz.

File metadata

  • Download URL: basictable-1.0.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.9.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for basictable-1.0.1.tar.gz
Algorithm Hash digest
SHA256 bf36edf0e90b8404e24291f808fe850684f48ff5870e9b92ce24ec66f33db5f3
MD5 979f39a8eb045fc0591b5fe4bf0ed758
BLAKE2b-256 af3c940aaafe3aa06992d82e3a36a2cbda698d797312323ed17ec8a1e0870fa2

See more details on using hashes here.

File details

Details for the file basictable-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: basictable-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.9.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for basictable-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 07279f3ad149556a3f0c19fb8b0f43a55e164162d0b8bcb3c9f15d97bc03f06e
MD5 6273e2cf4652e24138aa4f6d76748cb9
BLAKE2b-256 e9f5e1b4187e9d0cc5d1e04cc3b7f8d433ce151b6c5b84b1c481ed639504d2ef

See more details on using hashes here.

Supported by

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