Skip to main content

A package used to generate basic markdown tables from a list of dicts

Project description

markdownTable

GitHub Workflow Status codecov Downloads Downloads Downloads

A class used to generate padded tables in a markdown code block. It also works with pandas dataframes.

Installation

using pip: pip install py-markdown-table importing: from markdownTable import markdownTable

Usage

markdownTable(data).getMarkdown() or markdownTable(data).setParams(...).getMarkdown()

Parameters

The library supports has the following parameters:

markdownTable(data):
    data (list): List of dicts with uniform {key : value} pairs used to generate the header
markdownTable(data).setParams(...):
    row_sep (str): Row separation strategy with the following options:
            'always'        Separate each row
            'topbottom'     Insert row separator above header and below the last row
            'markdown'      Single header/body separator formated as valid markdown
            'None'          No row separation
    padding_width (int):    Extra padding to all table cells
    padding_weight (str):   Padding strategy. The following values are accepted:
            'left'          Aligns items to the end of the cell
            'right'         Aligns items to the beginning of the cell
            'centerleft'    Centers items, where extra padding is allocated to the beginning of the cell
            'centerright'   Centers items, where extra padding is allocated to the end of the cell
    padding_char (str):     Custom single character to fill extra and normal padding with. Default is a blank space.
    newline_char (str):     Custom character to be used for indicating a newline. Default is '\n'
    float_rounding (int):   Round down float values to a number decimal places.
                            Default is 2, but can also be set to 'None' to not round down.
    quote(bool):            If true (default) surrounds the table with markdown block code quote

Using it with a dataframe

import pandas as pd
from markdownTable import markdownTable

file = 'sample.csv'
df = pd.read_csv(file)
markdownTable(df.to_dict(orient='records')).getMarkdown()

Examples

markdownTable(data).setParams(row_sep = 'always').getMarkdown()

+----------------------------------------+
|    title   |    time   |   date  |seats|
+------------+-----------+---------+-----+
|Vrij Zwemmen|21:30-23:00|Wed 09.12|24/24|
+------------+-----------+---------+-----+
|Vrij Zwemmen|12:00-13:00|Thu 10.12|18/18|
+------------+-----------+---------+-----+
|Vrij zwemmen| 7:30-8:30 |Fri 11.12|18/18|
+------------+-----------+---------+-----+
|Vrij Zwemmen|13:15-14:15|Sat 12.12|18/18|
+----------------------------------------+

markdownTable(data).setParams(row_sep = 'topbottom').getMarkdown()

+----------------------------------------+
|    title   |    time   |   date  |seats|
|Vrij Zwemmen|21:30-23:00|Wed 09.12|24/24|
|Vrij Zwemmen|12:00-13:00|Thu 10.12|18/18|
|Vrij zwemmen| 7:30-8:30 |Fri 11.12|18/18|
|Vrij Zwemmen|13:15-14:15|Sat 12.12|18/18|
+----------------------------------------+

markdownTable(data).setParams(row_sep = 'markdown').getMarkdown()

|    title   |    time   |   date  |seats|
|------------|-----------|---------|-----|
|Vrij Zwemmen|21:30-23:00|Wed 09.12|24/24|
|Vrij Zwemmen|12:00-13:00|Thu 10.12|18/18|
|Vrij zwemmen| 7:30-8:30 |Fri 11.12|18/18|
|Vrij Zwemmen|13:15-14:15|Sat 12.12|18/18|

markdownTable(data).setParams(row_sep = 'markdown', quote = False).getMarkdown()

title time date seats
Vrij Zwemmen 21:30-23:00 Wed 09.12 24/24
Vrij Zwemmen 12:00-13:00 Thu 10.12 18/18
Vrij zwemmen 7:30-8:30 Fri 11.12 18/18
Vrij Zwemmen 13:15-14:15 Sat 12.12 18/18

markdownTable(data).setParams(row_sep = 'topbottom', padding_width = 5, padding_weight='left').getMarkdown()

+------------------------------------------------------------+
|            title|            time|          date|     seats|
|     Vrij Zwemmen|     21:30-23:00|     Wed 09.12|     24/24|
|     Vrij Zwemmen|     12:00-13:00|     Thu 10.12|     18/18|
|     Vrij zwemmen|       7:30-8:30|     Fri 11.12|     18/18|
|     Vrij Zwemmen|     13:15-14:15|     Sat 12.12|     18/18|
+------------------------------------------------------------+

markdownTable(data).setParams(row_sep = 'topbottom', padding_width = 5, padding_weight = 'centerright').getMarkdown()

+------------------------------------------------------------+
|      title      |      time      |     date     |  seats   |
|  Vrij Zwemmen   |  21:30-23:00   |  Wed 09.12   |  24/24   |
|  Vrij Zwemmen   |  12:00-13:00   |  Thu 10.12   |  18/18   |
|  Vrij zwemmen   |   7:30-8:30    |  Fri 11.12   |  18/18   |
|  Vrij Zwemmen   |  13:15-14:15   |  Sat 12.12   |  18/18   |
+------------------------------------------------------------+

mt = markdownTable(data).setParams(row_sep = 'always', padding_width = 5, padding_weight='centerright', padding_char = '.').getMarkdown()

+------------------------------------------------------------+
|......title......|......time......|.....date.....|..seats...|
+-----------------+----------------+--------------+----------+
|..Vrij Zwemmen...|..21:30-23:00...|..Wed 09.12...|..24/24...|
+-----------------+----------------+--------------+----------+
|..Vrij Zwemmen...|..12:00-13:00...|..Thu 10.12...|..18/18...|
+-----------------+----------------+--------------+----------+
|..Vrij zwemmen...|...7:30-8:30....|..Fri 11.12...|..18/18...|
+-----------------+----------------+--------------+----------+
|..Vrij Zwemmen...|..13:15-14:15...|..Sat 12.12...|..18/18...|
+------------------------------------------------------------+

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

py-markdown-table-0.2.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

py_markdown_table-0.2.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file py-markdown-table-0.2.2.tar.gz.

File metadata

  • Download URL: py-markdown-table-0.2.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for py-markdown-table-0.2.2.tar.gz
Algorithm Hash digest
SHA256 b48f14107771e560ec205d43a2f0a2e781a2ab20eb119e7614ba592f388cb34d
MD5 b978b477334c4daa817b70f8b973f16c
BLAKE2b-256 9d319bec469942a786474bac0a1011e409770c17ebf9aa88b905ca6ce0219f3b

See more details on using hashes here.

File details

Details for the file py_markdown_table-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: py_markdown_table-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for py_markdown_table-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5e949ae8c00a25b84544e63103f3ad33ccd79db4f6aa94b0eaa18cf9a9ae879a
MD5 c5f55a53f83c5ddd407c6105f279008e
BLAKE2b-256 ba4a2d96211884dabfa86079b49a123558eb67df31b39c33658281b333bff9dc

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