simple_html_table
Simple way to create HTML tables with support for rowspan and colspan attributes.
Usage
simple_html_table defines three classes that represent HTML tables, rows and cells respectively. To use the module, create a Table instance and pass it a 2D numpy array of strings, or a callable that will take Cell objects and return strings.:
from simple_html_table import Table
contents = [
["Head 1", "Head 2", "Head 3", "Head 4"],
["(1,1)", "(1,2)", "(1,3)", "(1,4)"],
["(2,1)", "(2,2)", "(2,3)", "(2,4)"],
]
table = Table((3, 4), table_contents=np.array(contents))
table[1, 1].colspan = 2
table[0, 0].rowspan = 3
table[0, 1].attrs_dict.update({"style": "{ background: red; }"})
table[0].header = True
for cell in table[0]:
cell.classes = "table_th"
result = table.render()
print(result,"\n")
def content_func(cell: Cell) -> str:
"""Callback function to fill in the table."""
row, col = cell.location
return contents[row][col]
table2 = Table((3, 4), table_contents=content_func)
result = table2.render()
print(result)
Output
<table class='html_table'>
<tr class='html_tr'>
<th class='table_th' rowspan=3>Head 1</th>
<th class='table_th' style='{ background: red; }'>Head 2</th>
<th class='table_th'>Head 3</th>
<th class='table_th'>Head 4</th>
</tr>
<tr class='html_tr'>
<td class='html_td' colspan=2>(1,2)</td>
<td class='html_td'>(1,4)</td>
</tr>
<tr class='html_tr'>
<td class='html_td'>(2,2)</td>
<td class='html_td'>(2,3)</td>
<td class='html_td'>(2,4)</td>
</tr>
</table>
<table class='html_table'>
<tr class='html_tr'>
<td class='html_td'>Head 1</td>
<td class='html_td'>Head 2</td>
<td class='html_td'>Head 3</td>
<td class='html_td'>Head 4</td>
</tr>
<tr class='html_tr'>
<td class='html_td'>(1,1)</td>
<td class='html_td'>(1,2)</td>
<td class='html_td'>(1,3)</td>
<td class='html_td'>(1,4)</td>
</tr>
<tr class='html_tr'>
<td class='html_td'>(2,1)</td>
<td class='html_td'>(2,2)</td>
<td class='html_td'>(2,3)</td>
<td class='html_td'>(2,4)</td>
</tr>
</table>
Table and Row objects implement mutable sequence interfaces, so can be indexed. A Table will except being indexed with a single integer to return a Row or with a tuple of two integers to return a Cell. A Row can be indexed to return Cell instances.
Cells know which Row they belong to and Tows know which Table they belong to. This means copying Cells and Rows will probably mess up unless you explicitly reset the pointers.
Colpan and Rowpans are implemented simply by storing references to the same Cell objects within the Row objects - as a result, it is always possible to index the Table, but the Cell returned may think it belongs to a different row and column within the table.
Metadata
Release files for simple-html-table 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simple_html_table-0.2.0.tar.gz | 10.3 kB | Without provenance | Details for simple_html_table-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simple_html_table-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for simple_html_table-0.2.0-py3-none-any.whl |
Total release size: 18.4 kB
Release files / simple_html_table-0.2.0.tar.gz
| Download URL | simple_html_table-0.2.0.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8cee525c3df8e96f5120348ccc3588cfc4a29e63d87e8c591eb81e24d3a1e151
|
|
BLAKE2b-256 checksum How to use checksums |
54603ad7ee26296a598ab3fab7a06abf844ea17d9d518b3418b859d61c904634
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.65.0 CPython/3.10.9
|
Release files / simple_html_table-0.2.0-py3-none-any.whl
| Download URL | simple_html_table-0.2.0-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
baebafa83ab43e47e6e739895a64e4b047df1a72528ae60c234e212f8d02ab69
|
|
BLAKE2b-256 checksum How to use checksums |
19904b06e7c802788b1e051abb9673ea97a39a14c7d02ef0c28db1de45a674dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.65.0 CPython/3.10.9
|
Security for simple-html-table 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.