Registry / serialization / mdutils

mdutils

JSON →
library1.8.1pypypi✓ verified 22d ago

mdutils is a useful Python package for programmatically creating Markdown files. It provides methods to generate headers, lists, tables, links, images, and format text while executing Python code. The current version is 1.8.1, and the library is actively maintained with regular updates including new features, bug fixes, and general maintenance.

pip install mdutils
INSTALL
IMPORT
SIG · MDUTILS
M
mdutils
serializationpythonv1.8.1
Install
1.5s avg
Import
21ms
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.8.1 · 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.022s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.020s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

MdUtils
from mdutils.mdutils import MdUtils

This quickstart demonstrates how to initialize the `MdUtils` class, add various Markdown elements like headers, paragraphs, lists, and tables, and then generate the `.md` file. The `create_md_file()` method is always the last call to write the content to disk.

from mdutils.mdutils import MdUtils # Create a Markdown file object mdFile = MdUtils(file_name='example_markdown', title='My Example Document') # Add a header mdFile.new_header(level=1, title='Introduction') mdFile.new_paragraph("This is an example of a Markdown file created using the mdutils library.") # Add a list mdFile.new_header(level=2, title='Features') items = [ 'Create Headers', 'Generate Tables', 'Add Lists', 'Insert Links and Images' ] mdFile.new_list(items=items, marked_with='-') # Add a table mdFile.new_header(level=2, title='Data Table') list_of_strings = [ 'Header 1', 'Header 2', 'Header 3', 'Row 1, Col 1', 'Row 1, Col 2', 'Row 1, Col 3', 'Row 2, Col 1', 'Row 2, Col 2', 'Row 2, Col 3' ] mdFile.new_table(columns=3, rows=3, text=list_of_strings, text_align='center') # Finalize and create the file mdFile.create_md_file() print("Markdown file 'example_markdown.md' created successfully.")
Debug
Known issues
gotchaThe `text_align` parameter for methods like `new_table` was enhanced in v1.3.1 to accept a list of strings for individual column alignment, in addition to a single string (`'left'`, `'center'`, `'right'`) for global alignment. Code expecting only a single string type for `text_align` might need adjustment if more granular control is desired or if type-checking is strict.
fix
Ensure `text_align` is a single string (e.g., `'center'`) for global alignment, or a list of strings (e.g., `['left', 'center', 'right']`) for column-specific alignment.
affects: >=1.3.1
gotchaBefore v1.8.1, using bold text (e.g., `**text**`) as an item in `new_list` could cause the list formatting to break. This bug was fixed in v1.8.1, so previous workarounds are no longer necessary.
fix
Upgrade to v1.8.1 or later. If unable to upgrade, avoid starting list items with Markdown bold syntax when using `new_list`.
affects: <1.8.1
deprecatedThe `new_line()` method previously added extra spaces in some scenarios. This was fixed in v1.7.0. If your application relied on or accounted for these extra spaces in its output parsing, its behavior might change.
fix
Upgrade to v1.7.0 or later to ensure correct spacing. Review any downstream parsing logic if you were handling unexpected spaces from `new_line()`.
affects: <1.7.0
gotchaPrior to v1.2.2, table of contents links generated by `MdUtils` might not work correctly if headers contained special characters. This issue was resolved, improving the robustness of TOC generation.
fix
Upgrade to v1.2.2 or later to ensure TOC links with special characters are correctly rendered. Older versions might require manual sanitization of header titles for reliable TOC links.
affects: <1.2.2
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'mdutils'
The 'mdutils' library has not been installed in the Python environment where the code is being executed.
fix
Install the library using pip: `pip install mdutils`
NameError: name 'MdUtils' is not defined
The 'MdUtils' class is imported incorrectly, often by using `import Mdutils` at the top level instead of importing the class directly from its module.
fix
Import the 'MdUtils' class directly from the 'mdutils.mdutils' module: `from mdutils.mdutils import MdUtils`
TypeError: For using bold_italics_code param, reference_tag must be defined
When calling the `new_reference_link` method and specifying the `bold_italics_code` parameter, the `reference_tag` parameter is mandatory and must also be provided.
fix
Ensure a value is provided for the `reference_tag` parameter whenever `bold_italics_code` is used with `new_reference_link`.
TypeError: text_align must be of type <class 'str'> (or <class 'list'>)
The `text_align` parameter for methods like `new_table` expects either a single string (e.g., 'center') for global alignment or a list of strings for column-specific alignment, and an incompatible type was provided.
fix
Pass `text_align` as a single string (e.g., `'center'`) for global alignment or a list of strings (e.g., `['left', 'center', 'right']`) for column-specific alignment, matching the expected type for your `mdutils` version and desired functionality.
Upgrade
Version history
1.8.1latest on PyPI · released Oct 18, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
mdutils — pip install mdutils · libregistry