SnakeMD

2.4.0 · active · verified Fri Apr 17

SnakeMD is a Python library designed for programmatically generating Markdown documents. It allows users to create headings, paragraphs, lists, tables, and other Markdown elements using a Pythonic API. The library is actively maintained, with version 2.4.0 being the latest stable release, and typically sees updates every few months.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic Markdown document with headings, paragraphs, lists, and tables, and then render it to a file using SnakeMD. It covers the core `Document` object and common content addition methods.

import snakemd

# Create a new Document
doc = snakemd.Document("My Article")

# Add a heading
doc.add_heading("Welcome to SnakeMD!")

# Add a paragraph
doc.add_paragraph("This is an example of how to use SnakeMD to generate Markdown.")

# Add an ordered list
doc.add_ordered_list(["First item", "Second item", "Third item"])

# Add a table
doc.add_table(
    headers=["Name", "Age"],
    data=[["Alice", "30"], ["Bob", "24"]]
)

# Output the Markdown to a file
# In a real scenario, you might want to save to a specific path
# and handle potential file I/O errors.
output_filename = os.environ.get('SNAKEMD_OUTPUT_FILE', 'output.md')
with open(output_filename, "w") as f:
    f.write(doc.render())

print(f"Markdown written to {output_filename}")

view raw JSON →