pdfkit
Wkhtmltopdf python wrapper to convert html to pdf using the webkit rendering engine and qt
What it is and what it does
pdfkit is a thin Python wrapper around the wkhtmltopdf command-line tool, which uses the Webkit rendering engine to convert HTML into PDF files. It lets you generate PDFs from live URLs, local HTML files, or HTML strings passed directly to the API, with support for options like page size, margins, headers, footers, and table of contents. The package handles the subprocess plumbing and argument construction so you don't have to shell out to wkhtmltopdf manually.
The wrapper requires wkhtmltopdf to be installed as a separate system binary; pdfkit itself has no Python runtime dependencies. It supports both Python 2 and 3 (though Python 2 is long obsolete) and offers a simple three-function API: from_url(), from_file(), and from_string(). You can also retrieve the PDF as a byte string instead of writing to disk, and pass detailed configuration options via dictionaries.
Use it for:
- Generate PDF reports from HTML templates in a web application without relying on a headless browser service.
- Batch-convert multiple HTML files or URLs to PDF for archival or distribution.
- Create invoices or receipts by rendering HTML with CSS styling directly to PDF.
- Embed PDF generation in a Python script that needs to produce documents from web content.
- Add table of contents, headers, and footers to HTML-based documents during PDF export.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Python wrapper for wkhtmltopdf that converts HTML to PDF using the Webkit rendering engine, supporting URLs, files, and HTML strings as input.
Yes, if you need simple HTML-to-PDF conversion and are willing to manage the wkhtmltopdf system dependency. The package is stable and widely used, but dormant—no active maintenance since late 2023. Check the two known vulnerabilities before use in security-sensitive contexts. For new projects, consider whether a maintained alternative or headless-browser service better fits your risk tolerance.
Install
pdfkit on PyPI
pip
pip install pdfkituv
uv add pdfkitpoetry
poetry add pdfkitInstalling pdfkit
Before you install
Low install friction with no runtime dependencies. However, the package is dormant—last release was 2021-11-14 and last commit 2023-10-26—so expect no active maintenance or updates for emerging issues.
License in practice
MIT license is permissive, allowing commercial and private use with minimal restrictions.
Quickstart
pip install pdfkit
import pdfkit
pdfkit.from_url('http://google.com', 'out.pdf')
pdfkit.from_file('test.html', 'out.pdf')
pdfkit.from_string('Hello!', 'out.pdf')
wkhtmltopdf binary must be installed separately on your system (via apt-get, brew, or direct download); pdfkit is only a Python wrapper and will not function without it.
Verify before relying
- Current compatibility with modern Python versions beyond 3.9 (classifiers list 3.9 as latest)
- Status of the two known vulnerabilities (GHSA-9g3x-6x24-vf9f, PYSEC-2026-2860) and whether they affect typical use
- Whether Debian/Ubuntu wkhtmltopdf packages still have reduced functionality as documented
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 1,734 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 7,782,391/month — #1,696 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | 2 — GHSA-9g3x-6x24-vf9f, PYSEC-2026-2860 |
Evidence: pdfkit-1.0.0-py2-none-any.whl; pdfkit-1.0.0-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
django-wkhtmltopdfWraps the wkhtmltopdf binary to convert HTML to…
permissive · top 15,000 on PyPI
imgkitimgkit wraps the wkhtmltoimage command-line…
permissive · top 15,000 on PyPI
wkhtmltopdfWraps the wkhtmltopdf command-line tool to…
permissive · top 15,000 on PyPI
weasyprintWeasyPrint converts HTML and CSS into PDF…
permissive · top 1,000 on PyPI
markdown-pdfConverts markdown text to PDF files, with…
agpl · top 15,000 on PyPI
xhtml2pdfConverts HTML and CSS to PDF documents using…
permissive · top 5,000 on PyPI
md2pdfConverts Markdown files to PDF with custom CSS…
permissive · top 15,000 on PyPI
fpdfGenerates PDF documents from Python code,…
copyleft · top 5,000 on PyPI
nokapnokap captures screenshots and PDFs from web…
permissive · top 15,000 on PyPI
ghostscriptProvides a Python interface to the Ghostscript…
copyleft · top 15,000 on PyPI