Skip to main content

Python SDK for html2pdfconverter.com

Project description

html2pdfconverter Python SDK

Lightweight Python client for https://api.html2pdfconverter.com. Mirrors the Node SDK features: create conversion jobs from HTML, URLs, or local files; poll for completion; download PDFs to memory or disk; and verify webhooks.

Installation

pip install html2pdfconverter

Quickstart

from html2pdfconverter import PdfClient

client = PdfClient(api_key="YOUR_API_KEY")

# Convert a URL and get PDF bytes
pdf_bytes = client.convert({"url": "https://example.com"})

# Convert inline HTML and save directly to disk
output_path = client.convert(
    {
        "html": "<h1>Hello</h1>",
        "pdf_options": {"format": "A4"},
        "save_to": "output.pdf",
    }
)

# Submit a job with webhook (returns jobId immediately)
job_id = client.convert({"url": "https://example.com", "webhook_url": "https://yourapp.com/webhook"})

API

PdfClient(options)

  • api_key (str, required): Your API key.
  • base_url (str, optional): Defaults to https://api.html2pdfconverter.com.
  • webhook_secret (str, optional): Required for webhook verification.

convert(options) -> bytes | str

Creates a conversion job. Accepts one of:

  • html (str): Raw HTML string.
  • url (str): URL to render.
  • file_path (str): Path to an HTML file.

Optional:

  • pdf_options (dict): Options passed through to the service.
  • webhook_url (str): If provided, returns jobId immediately and expects webhook delivery.
  • poll_interval_ms (int): Poll cadence, default 2000.
  • timeout_ms (int): Poll timeout, default 300000.
  • save_to (str): Path to write the PDF. Returns the path when set; otherwise returns PDF bytes.

get_job(job_id, options) -> bytes | str

Polls for job completion and downloads the PDF (similar options to convert).

verify_webhook(raw_body, signature) -> dict

Validates webhook signatures using the webhook_secret provided to the client and returns the parsed JSON payload.

Webhook verification example

from flask import Flask, request, abort
from html2pdfconverter import PdfClient

client = PdfClient(api_key="YOUR_API_KEY", webhook_secret="WEBHOOK_SECRET")

app = Flask(__name__)

@app.route("/webhook", methods=["POST"])
def webhook():
    signature = request.headers.get("x-webhook-signature")
    try:
        payload = client.verify_webhook(request.data, signature)
    except Exception:
        abort(400)
    # handle payload...
    return "", 200

Notes

  • Retries are automatically applied to transient 502 responses.
  • When sending inline HTML, a temporary file is created and cleaned up automatically before upload.
  • The download step streams to disk when save_to is provided to avoid loading large PDFs into memory.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

html2pdfconverter-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

html2pdfconverter-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file html2pdfconverter-0.1.0.tar.gz.

File metadata

  • Download URL: html2pdfconverter-0.1.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for html2pdfconverter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 50b62525e10f04cfdd71c4d7bfddd25dc074ec90bc389d87a99f4d3a9c39f1a7
MD5 8e1c20ccc9aa7c0ca002c742ee99e43d
BLAKE2b-256 534e0347795cdacdf4566e6ea896938777bdd97fccc299f792be16c71dad2cc3

See more details on using hashes here.

File details

Details for the file html2pdfconverter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for html2pdfconverter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 86e56dab026d59ba0cf614a7c95e6586b753cbbfdc79d8386983ef0b966167d6
MD5 9c1ab85082a0019c1f0ee102244dec3a
BLAKE2b-256 0e24033c51b389b391fb67255b488cecc91d4ccf7cd9b12e04e295b81e18ca3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page