Using Markdown as a Python Library

First and foremost, Python-Markdown is intended to be a python library module used by various projects to convert Markdown syntax into HTML.

The Basics

To use markdown as a module:

import markdown
html = markdown.markdown(your_text_string)

The Details

Python-Markdown provides two public functions (markdown.markdown and markdown.markdownFromFile) both of which wrap the public class markdown.Markdown. If you're processing one document at a time, the functions will serve your needs. However, if you need to process multiple documents, it may be advantageous to create a single instance of the markdown.Markdown class and pass multiple documents through it.

markdown.markdown(text [, **kwargs])

The following options are available on the markdown.markdown function:

markdown.markdownFromFile(**kwargs)

With a few exceptions, markdown.markdownFromFile accepts the same options as markdown.markdown. It does not accept a text (or Unicode) string. Instead, it accepts the following required options:

markdown.Markdown([**kwargs])

The same options are available when initializing the markdown.Markdown class as on the markdown.markdown function, except that the class does not accept a source text string on initialization. Rather, the source text string must be passed to one of two instance methods: