{"id":1869,"library":"pypandoc","title":"Pypandoc","description":"Pypandoc is a Python wrapper for Pandoc, a powerful universal document converter. It simplifies the process of converting files between various formats such as Markdown, HTML, DOCX, PDF, LaTeX, ODT, and EPUB. The library is actively maintained, with the current version being 1.17, and it follows a regular release cadence to incorporate updates and improvements.","status":"active","version":"1.17","language":"en","source_language":"en","source_url":"https://github.com/JessicaTegner/pypandoc","tags":["document conversion","pandoc","markdown","html","pdf","docx","latex","converter"],"install":[{"cmd":"pip install pypandoc","lang":"bash","label":"Basic installation (requires pre-installed Pandoc)"},{"cmd":"pip install pypandoc_binary","lang":"bash","label":"Includes Pandoc binary (for Windows/macOS/some Linux)"},{"cmd":"pip install pypandoc[tinytex]","lang":"bash","label":"Includes Pandoc & TinyTeX (for seamless PDF conversion)"},{"cmd":"conda install -c conda-forge pypandoc","lang":"bash","label":"Conda installation (includes Pandoc)"}],"dependencies":[{"reason":"Pypandoc is a wrapper for Pandoc; the Pandoc executable must be installed and accessible in the system PATH, or implicitly provided by `pypandoc_binary`/`pypandoc[tinytex]` packages.","package":"pandoc","optional":false},{"reason":"Optional, provides automatic LaTeX distribution for PDF conversions via `pypandoc[tinytex]`.","package":"pytinytex","optional":true}],"imports":[{"note":"The `convert()` function was deprecated in v1.7.0 and removed in v1.8. Use `convert_file()` for file-based conversion or `convert_text()` for string-based conversion.","wrong":"pypandoc.convert(...)","symbol":"convert_file","correct":"import pypandoc\npypandoc.convert_file('input.md', 'pdf', outputfile='output.pdf')"},{"note":"Use `convert_text()` for converting strings. It expects unicode or utf-8 encoded bytes and returns a unicode string.","symbol":"convert_text","correct":"import pypandoc\nhtml_output = pypandoc.convert_text('# Hello', 'html', format='md')"}],"quickstart":{"code":"import pypandoc\nimport os\n\n# Ensure pandoc is available (optional if using pypandoc_binary or pypandoc[tinytex])\n# pypandoc.download_pandoc() # uncomment if you installed pypandoc without binary and don't have pandoc\n\n# Create a dummy markdown file\nwith open('input.md', 'w') as f:\n    f.write('# Hello from Pypandoc\\n\\nThis is a test document.')\n\n# Convert markdown file to PDF (requires pandoc and a LaTeX distribution like TinyTeX)\n# For seamless PDF conversion, install with `pip install pypandoc[tinytex]`\npypandoc.convert_file('input.md', 'pdf', outputfile='output.pdf')\nprint(\"Converted input.md to output.pdf\")\n\n# Convert markdown string to HTML\nhtml_output = pypandoc.convert_text('# Another Title\\n\\nSome **bold** text.', 'html', format='md')\nprint(\"Converted Markdown string to HTML:\")\nprint(html_output)\n\n# Clean up dummy files\nos.remove('input.md')\nos.remove('output.pdf')","lang":"python","description":"This quickstart demonstrates how to convert a Markdown file to PDF and a Markdown string to HTML using `pypandoc`. For PDF conversion, installing `pypandoc[tinytex]` simplifies LaTeX setup. If `pypandoc_binary` is not used, ensure Pandoc is installed on your system or use `pypandoc.download_pandoc()`."},"warnings":[{"fix":"Upgrade to Python 3 or pin pypandoc version to <1.8.","message":"Python 2 support was officially dropped in pypandoc v1.8. Users on Python 2 must use an older version of pypandoc.","severity":"breaking","affected_versions":">=1.8"},{"fix":"Replace `pypandoc.convert(source, to, format, ...)` with `pypandoc.convert_file(source_path, to_format, outputfile, ...)` for files or `pypandoc.convert_text(source_string, to_format, format, ...)` for strings.","message":"The `pypandoc.convert()` function was deprecated in v1.7.0 and removed in v1.8. Direct usage will raise an error.","severity":"breaking","affected_versions":">=1.8"},{"fix":"Install `pandoc` on your system, use `pip install pypandoc_binary`, or utilize `pypandoc.download_pandoc()` to install it through the library. Ensure Pandoc's executable is in your system's PATH.","message":"Pypandoc requires a working Pandoc installation. If you install `pypandoc` (without `_binary` or `[tinytex]`), you must install Pandoc separately via your system's package manager or manually. An `OSError` will be raised if Pandoc is not found.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review Pandoc's documentation on sandbox mode. If necessary, you can typically disable it via `extra_args` or library configuration, though it's recommended to understand the security implications.","message":"Pandoc's sandbox mode (for security) is enabled by default for Pandoc versions >= 2.15 when used via pypandoc v1.7.0 and newer. This might affect how certain filters or file operations behave.","severity":"gotcha","affected_versions":">=1.7.0 (with Pandoc >= 2.15)"},{"fix":"Instead of `extra_args='-V key=value'`, use `extra_args=['-V', 'key=value']`.","message":"When passing `extra_args` to `pypandoc.convert_file` or `convert_text`, arguments and their values (like `-V key=value`) must be passed as separate items in a list due to `subprocess.Popen` behavior.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install `pypandoc[tinytex]` for automatic setup, or install a full LaTeX distribution manually and ensure it's in your system's PATH.","message":"For PDF conversion, Pandoc requires a LaTeX distribution (e.g., TeX Live, MiKTeX). Installing `pypandoc[tinytex]` simplifies this by automatically downloading and managing TinyTeX, but if not used, manual LaTeX setup is required.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}