Registry / serialization / py-markdown-table

py-markdown-table

JSON →
library1.3.0pypypi✓ verified 24d ago

py-markdown-table is an active Python library, currently at version 1.3.0, designed to generate formatted markdown tables from a list of dictionaries. It boasts zero dependencies and releases updates periodically, addressing bug fixes and enhancing formatting options.

pip install py-markdown-table
INSTALL
IMPORT
SIG · PY-MARKDOWN-TABLE
P
py-markdown-table
serializationpythonv1.3.0
Install
1.6s avg
Import
12ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.012s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.010s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

markdown_table
from py_markdown_table.markdown_table import markdown_table
from markdownTable import markdownTable
The import path was changed in preparation for v1.0.0. The old namespace `markdownTable` was deprecated and fully removed in v1.0.0.

This example demonstrates how to create a basic markdown table from a list of dictionaries. The keys of the dictionaries become the column headers, and the values form the rows of the table.

from py_markdown_table.markdown_table import markdown_table data = [ {"Product": "Smartphone", "Brand": "Apple", "Price": 999.99}, {"Product": "Laptop", "Brand": "Dell", "Price": 1299.99} ] markdown = markdown_table(data).get_markdown() print(markdown)
Debug
Known issues
breakingThe import namespace changed from `markdownTable` to `py_markdown_table.markdown_table` in v1.0.0. Older versions (<1.0.0, e.g., v0.4.0) provided a warning about this impending change.
fix
Update your import statements from `from markdownTable import markdownTable` to `from py_markdown_table.markdown_table import markdown_table`.
affects: <1.0.0
breakingDeprecated methods were removed in v1.0.0 as part of a code cleanup and simplification.
fix
Refer to the v1.0.0 changelog and updated documentation on GitHub for current method equivalents and refactor your code accordingly.
affects: <1.0.0
gotchaThe library expects input data as a list of dictionaries where all dictionaries (rows) must have uniform keys (column headers). Inconsistent keys may lead to unexpected table structures or errors.
fix
Ensure all dictionary items in your input list share the exact same keys to represent consistent columns across all rows.
affects: All
gotchaData validation was added in v1.0.0 for robustness. If your data might not strictly adhere to expected formats, you can skip validation using the `skip_data_validation` parameter in the constructor.
fix
If experiencing issues with new validation rules, consider reviewing your data or setting `skip_data_validation=True` as a temporary workaround, understanding the potential risks.
affects: >=1.0.0
gotchaRendering of multiline content and emojis can vary between different Markdown viewers. GitHub's markdown preview, for instance, might show slight offsets in cells containing emojis compared to a monospaced terminal.
fix
Test your generated markdown in the target rendering environment (e.g., GitHub, specific IDEs, or documentation tools) to ensure it appears as intended, especially for complex layouts or heavy emoji use.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'py_markdown_table'
The `py-markdown-table` library is installed, but the user is trying to import it using an incorrect module name or path. The main class `markdown_table` resides within the `py_markdown_table.markdown_table` submodule.
fix
Ensure the correct module path is used for importing the `markdown_table` class.
```python
from py_markdown_table.markdown_table import markdown_table
```
AttributeError: 'module' object has no attribute 'markdown_table'
This typically occurs when a user attempts `import py_markdown_table` and then tries to access `py_markdown_table.markdown_table` without realizing that `markdown_table` is a class within a submodule, not directly under the top-level package.
fix
The `markdown_table` class needs to be imported from its specific submodule.
```python
from py_markdown_table.markdown_table import markdown_table
```
TypeError: 'list' object is not callable
The `markdown_table` constructor expects a list of dictionaries. This error might occur if a user incorrectly tries to call a list object as if it were a function, or if they've somehow overwritten a variable name, but more commonly, it indicates a fundamental misunderstanding of passing the data to the constructor or subsequent method chaining.
fix
Ensure that the `markdown_table` class is instantiated correctly with the list of dictionaries, and that subsequent operations are method calls on the created object, not attempts to call the data list itself.
```python
from py_markdown_table.markdown_table import markdown_table
data = [
    {"Header1": "Value1", "Header2": "Value2"},
    {"Header1": "Value3", "Header2": "Value4"}
]
markdown = markdown_table(data).get_markdown()
```
AttributeError: 'markdown_table' object has no attribute 'build'
After instantiating the `markdown_table` class and optionally setting parameters, users might try to call a non-existent method to finalize the markdown string. The correct method to get the formatted markdown output is `get_markdown()`.
fix
After configuring the `markdown_table` object, call the `get_markdown()` method to retrieve the final markdown string.
```python
from py_markdown_table.markdown_table import markdown_table
data = [
    {"ColA": "Data1", "ColB": "Data2"}
]
markdown_obj = markdown_table(data)
# ... (optional set_params calls) ...
final_markdown = markdown_obj.get_markdown()
print(final_markdown)
```
Upgrade
Version history
1.3.0latest on PyPI · released Feb 6, 2025
Audit
Dependencies
pythonrequiredRequired Python version compatibility.
Agent activity
8 hits · last 30 days
node
6
Resources
py-markdown-table — pip install py-markdown-table · libregistry