Python 3 library to create properly aligned Markdown tables
Project description
Python Markdown tables
With this simple library you can easily generate the Markdown source code for a table.
The library is written for Python 3. As of now it's only been tested with version 3.7 of the language, but I think it should also work with 3.6. Open an issue to let me know how it goes!
Example
from mdtables import Table, Column
t = Table(
Column('n'),
Column('2·n', alignment='center'),
Column('n²', alignment='right' )
)
numbers = (1, 6, 19, 59)
for n in numbers:
t.row(n, 2*n, n*n)
print(t)
prints
|n |2·n| n²|
|--|:-:|---:|
|1 | 2 | 1|
|6 |12 | 36|
|19|38 | 361|
|59|118|3481|
Column options
header
: the only required argument: the name of the column.alignment
: how text should be aligned in the column. Possible values areleft
(default),center
andright
.width
: the width of the column. The default isNone
, which uses the smallest possible width that fits all content.format
: the format option used on all data inside cells (not in the header). This is part of a Python format string, it will be used like this:'{:
<width><alignment><format option comes here>}'.format(…)
. The default isstr.format
's default (like when you use just{}
without any formatting options).headerformat
: the format option used on the header. Analog toformat
above.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mdtables-1.1.0.tar.gz
(16.5 kB
view details)
Built Distribution
mdtables-1.1.0-py3-none-any.whl
(17.2 kB
view details)
File details
Details for the file mdtables-1.1.0.tar.gz
.
File metadata
- Download URL: mdtables-1.1.0.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c27d0bd930d6749968827a64cd46caa27c27680a4148bb80b7992b78fd495975 |
|
MD5 | 1716a9acb00d730b28cfc321f685c91e |
|
BLAKE2b-256 | 9d652214d3cf84b48f9aae3dbc618c0ecf09342b949a15c09c6ada7f6478cafd |
File details
Details for the file mdtables-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: mdtables-1.1.0-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9778913b627676b36e98480644c380a59ccf1bc1d2456767db9ef732bf0b7c3 |
|
MD5 | 0832277eedfcdceab9c2fbca18e88694 |
|
BLAKE2b-256 | 33ee34ed47d940622eaa1b1ac1ef4813309afdc4f5b0fce72f7a109c7b9a0708 |