Pandoc (Python Library)
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore add .gitignore Feb 7, 2016
.travis.yml test python 3 on travis Mar 24, 2016 fix README.txt ref in Mar 18, 2016 version 1.0.0b1 Mar 18, 2016 fix types removal Oct 18, 2017

Pandoc (Python Library)

PyPi Python Status Build Status

Warning. This project is not a Python binding for pandoc, the command-line tool. If this is what you need, you can either use pypandoc, pyandoc, etc., or create you own wrapper with subprocess or sh.

This library provides a Pythonic way to analyze, create and transform documents. It targets the pandoc power users which are more productive in Python than in Haskell (the native language of the pandoc library).

The pandoc Python library translates documents between the native pandoc JSON format and a Python document model. If you need to manage other formats (html, latex, etc.) use the pandoc command-line tool to convert to/from the JSON format.

This library is still in the beta stage and not documented. To get a better feel of the Python document model (an automated translation of the Haskell one), have a look at the test suite. The typical workflow is the following:

  1. Get a document in the JSON format:

    >>> json_input = [{"unMeta":{}},[{"t":"Para","c":[{"t":"Str","c":"Hello"}]}]]

    To be honest, I got this one with the commands:

    >>> import json, os
    >>> file = os.popen('echo "Hello" | pandoc -t json')
    >>> json_input = json.load(file)
  2. Read it as a Python document

    >>> import pandoc
    >>> doc =
    >>> doc
    Pandoc(Meta(map()), [Para([Str(u'Hello!')])])
  3. Analyze and/or transform the document

    >>> from pandoc.types import Space, Str
    >>> doc[1][0][0].extend([Space(), Str(u"World!")])
    >>> doc
    Pandoc(Meta(map()), [Para([Str(u'Hello'), Space(), Str(u'World!')])])
  4. Export the resulting document to JSON

    >>> json_output = pandoc.write(doc)

    and maybe, generate its HTML version:

    >>> import json, os     
    >>> json.dump(json_output, open("doc.json", "w"))
    >>> os.system("pandoc doc.json")
    <p>Hello World!</p>