mdutils

1.8.1 · active · verified Sun Apr 12

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.

Warnings

Install

Imports

Quickstart

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.")

view raw JSON →