pypandoc-binary: Pandoc Python Wrapper with Bundled Binary

1.17 · active · verified Thu Apr 09

pypandoc-binary is a thin Python wrapper for Pandoc that conveniently includes the Pandoc executable directly within its wheels, eliminating the need for users to manually install Pandoc. It is actively maintained with a somewhat irregular but consistent release cadence, with the current version being 1.17.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates converting Markdown text to reStructuredText and converting a Markdown file to an HTML file using `pypandoc-binary`. The `pypandoc` module is used for all operations, and the bundled Pandoc executable is utilized automatically.

import pypandoc
import os

# pypandoc-binary includes the pandoc executable in its wheel.
# No manual download is typically needed unless you want a different version.

markdown_text = "# Hello, World!\n\nThis is some **Markdown** content."

# Convert Markdown text to reStructuredText
try:
    rst_output = pypandoc.convert_text(markdown_text, 'rst', format='md')
    print("Converted to reStructuredText:\n" + rst_output)

    # Convert Markdown file to HTML file
    with open('input.md', 'w') as f:
        f.write(markdown_text)

    pypandoc.convert_file('input.md', 'html', outputfile='output.html')
    print("\nConverted input.md to output.html")
    with open('output.html', 'r') as f:
        print("\nContent of output.html:\n" + f.read()[:100] + '...') # Print first 100 chars

finally:
    # Clean up created files
    for f in ['input.md', 'output.html']:
        if os.path.exists(f):
            os.remove(f)

view raw JSON →