Skip to main content

Official Python SDK for the PDFik PDF generation API

Project description

pdfik

Official Python SDK for PDFik — the premium, fast, and reliable PDF generation API.

Convert HTML markup or any public URL into pixel-perfect PDF documents in seconds, powered by scalable browser rendering.

Features

  • Type Safety: Type hints for all options and response objects.
  • Sync & Async: Exposes both PdfikClient and AsyncPdfikClient using the modern httpx engine.
  • Auto Retry: Automatic exponential backoff for 5xx and 429 (Rate Limit) errors powered by tenacity.
  • DX Affordances: Built-in polling logic (wait_for_job) and file download helpers.

Installation

pip install pdfik

Quick Start

Convert public URL to PDF (Sync)

from pdfik import PdfikClient, PdfOptions, MarginOptions

# Initialize the client
client = PdfikClient(api_key="sk_live_...")

# 1. Submit the URL to be rendered
job = client.url_to_pdf(
    "https://example.com",
    options=PdfOptions(
        format="A4",
        landscape=False,
        print_background=True,
        margin=MarginOptions(top="10mm", bottom="10mm")
    )
)

print(f"Job created: {job.job_id}. Waiting for rendering...")

# 2. Poll until the job completes
result = client.wait_for_job(job.job_id)
print(f"Job finished! Pages: {result.pages_count}")

# 3. Download the PDF bytes
pdf_bytes = client.download_pdf(job.job_id)

with open("output.pdf", "wb") as f:
    f.write(pdf_bytes)
print("PDF saved to output.pdf")

# Close connection pool
client.close()

Convert raw HTML to PDF (Async)

import asyncio
from pdfik import AsyncPdfikClient, PdfOptions

async def main():
    async with AsyncPdfikClient(api_key="sk_live_...") as client:
        job = await client.html_to_pdf(
            "<h1>Hello World</h1><p>Sent from PDFik Python SDK</p>",
            options=PdfOptions(format="Letter")
        )
        
        result = await client.wait_for_job(job.job_id)
        print(f"Job finished! Status: {result.status}")
        
        pdf_bytes = await client.download_pdf(job.job_id)

asyncio.run(main())

Get a temporary, pre-signed download URL

If you prefer not to download the bytes directly through your application server, you can generate a secure pre-signed URL (expires in 15 minutes) for the user's browser to download:

file_info = client.get_file_url(job.job_id)
print(f"Download URL: {file_info.download_url}")

License

MIT License.

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

pdfik-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

pdfik-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pdfik-0.1.0.tar.gz
Algorithm Hash digest
SHA256 29c09deb40fb560986d8b6845154cacdcc193841fe63c5c89a8e7d81bf9acbfb
MD5 884f0f3026cd6d092750d4bf17c170be
BLAKE2b-256 fde89479fde777cb1e83d46631b4d8a3bd4a4e32e3373460592d2aca781d5b23

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdfik-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for pdfik-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13039f34263890d602e6d249cb94e6f3c61c4aa428270dc44af5ba3b7abd1908
MD5 d9bf0c9848cb8fda884cd8f9b1b04b41
BLAKE2b-256 e244f24babc705b8478bf74e9a6a25a2920e9c5187d09402ec673e2d9468216c

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