weasyprint

HTML/CSS to PDF converter for Python — renders HTML documents with full CSS support (including print media queries, flexbox, grid, paged media) to PDF. weasyprint features: HTML(string=)/HTML(filename=)/HTML(url=) input, document.write_pdf(target)/write_png(), @page CSS rules for margins/headers/footers, CSS counter() for page numbers, multi-column layouts, proper page breaks, font embedding, image support, running elements for headers/footers, CSS @media print support, and command-line usage. Produces publication-quality PDFs from HTML templates.

Evaluated Mar 06, 2026 (0d ago) v61.x
Homepage ↗ Repo ↗ Developer Tools python weasyprint pdf html css print report invoice
⚙ Agent Friendliness
66
/ 100
Can an agent use this?
🔒 Security
87
/ 100
Is it safe for agents?
⚡ Reliability
78
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
82
Error Messages
78
Auth Simplicity
99
Rate Limits
99

🔒 Security

TLS Enforcement
88
Auth Strength
88
Scope Granularity
85
Dep. Hygiene
85
Secret Handling
88

HTML-to-PDF converter. External URL input can trigger SSRF — validate URLs and HTML source. User-controlled HTML can embed external resources during rendering. PDF output may contain embedded content from untrusted sources. System library vulnerabilities (Cairo/Pango) affect security.

⚡ Reliability

Uptime/SLA
78
Version Stability
80
Breaking Changes
78
Error Recovery
78
AF Security Reliability

Best When

Generating PDF reports, invoices, and documents from HTML/CSS templates — weasyprint produces the highest-quality PDFs from HTML with proper CSS paged media support.

Avoid When

Interactive/fillable PDFs (use reportlab), minimal environments without system graphics libs, high-throughput PDF generation, or when WeasyPrint's heavy dependencies are a concern.

Use Cases

  • Agent PDF from HTML — from weasyprint import HTML; HTML(string='<html><body><h1>Report</h1></body></html>').write_pdf('report.pdf') — string input; agent generates PDF from HTML string; minimal setup; full CSS supported including web fonts if available
  • Agent template-based PDF — from jinja2 import Template; from weasyprint import HTML; template = Template(open('invoice.html').read()); html = template.render(invoice=data); HTML(string=html).write_pdf('invoice.pdf') — Jinja2 template; agent generates professional PDFs from HTML templates with dynamic data
  • Agent PDF with CSS — css = weasyprint.CSS(string='@page { size: A4; margin: 2cm; } body { font-family: Arial; }'); HTML(string=html).write_pdf('styled.pdf', stylesheets=[css]) — custom CSS; agent applies custom styles including page size, margins, headers/footers; CSS(filename=) for external stylesheet file
  • Agent PDF bytes — pdf_bytes = HTML(string=html_content).write_pdf(); response.headers['Content-Type'] = 'application/pdf'; return pdf_bytes — bytes output; agent generates PDF bytes for HTTP response without writing to disk; write_pdf() without target returns bytes
  • Agent URL to PDF — HTML(url='https://example.com').write_pdf('snapshot.pdf') — URL conversion; agent converts web page to PDF; fetches HTML and all referenced CSS/images; network requests required; useful for archiving or printing remote pages

Not For

  • Complex interactive PDFs — weasyprint generates static PDFs; for fillable forms and JavaScript PDF use reportlab or PyPDF2
  • Environments without Cairo/Pango — weasyprint requires system graphics libraries (Cairo, Pango, GDK-PixBuf); not usable in minimal containers without setup
  • High-throughput PDF generation — weasyprint is designed for quality not volume; for high-volume PDF use reportlab PLATYPUS or server-side puppeteer

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

No auth — PDF generation library. URL input may require authentication headers for protected resources.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

WeasyPrint is BSD 3-Clause licensed. Free for all use. Requires system Cairo/Pango libraries.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • System libraries required — weasyprint needs Cairo, Pango, GDK-PixBuf, and libffi; installation: macOS: brew install cairo pango gdk-pixbuf libffi; Ubuntu: apt-get install libpango-1.0-0 libharfbuzz0b libpangoft2-1.0-0; Debian Docker: python:3.x-slim + apt installs; agent Docker images: include library installs in Dockerfile; pip install alone is insufficient
  • Fonts must be installed — web fonts via @font-face require font files accessible to the system; Google Fonts URLs work only if network accessible; agent code for consistent PDF: bundle font files and use CSS @font-face with local paths; system fonts (Arial, Times) may not exist on minimal servers; use fonttools to verify font availability
  • write_pdf() target argument — HTML(string=html).write_pdf('file.pdf') writes to file; HTML(string=html).write_pdf() returns bytes; HTML(string=html).write_pdf(target=io.BytesIO()) writes to buffer; agent code: use write_pdf() for bytes (web response); write_pdf('path') for file; do not pass None to target
  • External resources resolve relative to base URL — HTML(string=html).write_pdf() has no base URL — relative CSS/image paths fail; HTML(string=html, base_url='file:///app/templates/').write_pdf() resolves relatives from that directory; agent code with relative paths: always set base_url to template directory
  • CSS @page for page size and margins — default page size is A4; change: CSS(string='@page { size: Letter landscape; margin: 1in; }') as stylesheet; @top-center { content: 'Header'; } for headers; counter(page) for page numbers; agent code: add stylesheets parameter not inline style for @page rules: HTML(string=html).write_pdf(stylesheets=[CSS(string='@page {...}')])
  • URL input fetches external resources — HTML(url=url) makes HTTP requests for CSS, images, fonts; slow for pages with many resources; agent code processing untrusted HTML: use string= not url= to avoid SSRF; HTML(string=user_html, base_url=None) prevents external requests; validate HTML source before passing to weasyprint

Alternatives

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for weasyprint.

$99

Scores are editorial opinions as of 2026-03-06.

5208
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered