Convert a URL to PDF in Python with requests
requests posts the url and parses the receipt; a second authenticated GET brings back the bytes, and Path.write_bytes puts them on disk.
The endpoint holds the connection until the render finishes, so the script is linear: POST, read the receipt, GET the download, write the file. The 60 second client timeout matches the endpoint's own render budget, and json= sets the request's Content-Type for you.
The recipe
import requests
from pathlib import Path
ORIGIN = "https://webcapture.io"
receipt = requests.post(
f"{ORIGIN}/v1/convert",
headers={"Authorization": "Bearer wc_your_key", "Content-Type": "application/json"},
json={"url": "https://example.com/"},
timeout=60,
).json()
# receipt["download"] names /v1/conversions/<id>.pdf at the serving origin
# and only answers to your key: send the same header
pdf = requests.get(
receipt["download"],
headers={"Authorization": "Bearer wc_your_key"},
timeout=60,
)
pdf.raise_for_status()
Path("page.pdf").write_bytes(pdf.content)
The receipt carries id, bytes, attempts, remaining, sourceUrl, sourceType, and download, and remaining is the count left on the account's monthly quota after this render. raise_for_status turns a failed render (502 for a page that would not load) or an exhausted quota (429) into an exception instead of writing an error body to disk. The download GET repeats the Authorization header because the endpoint is key-scoped, as every recipe here repeats it.
Same-key GET: 401 without it; 404 for another key.
The fields this recipe uses
url: the page address to render, a public http(s) URL.
Related
- Next: Get a free key to run this Python recipe, or read the API docs.
- More recipes: Python: wait for the page, curl: convert from a URL, Node: convert from a URL.
- The webcapture API reference: every field the convert endpoint admits, with the response shapes and the error table.
- The recipes hub: the same endpoint in the other languages.
- Going deeper: if this is a migration, the Python wkhtmltopdf guide maps pdfkit's options onto the same call.
- The free URL to PDF tool: try the render in a browser before you wire the call.
Method
Source: convert field reference, checked 2026-10-05. Corrections.