Skip to main content

Python SDK for the Forme hosted PDF API

Project description

forme

Python SDK for the Forme hosted PDF API.

Installation

pip install formepdf

Quick Start

from formepdf import Forme

client = Forme("forme_sk_...")

# Render a template to PDF bytes
pdf = client.render("invoice", {"customer": "Acme", "total": 100})

with open("invoice.pdf", "wb") as f:
    f.write(pdf)

API Reference

Forme(api_key, base_url="https://api.formepdf.com")

Create a client instance.

client.render(slug, data=None, *, s3=None)

Render a template synchronously. Returns bytes (PDF), or a dict with {"url": "..."} when s3 is provided.

# Direct PDF bytes
pdf = client.render("invoice", {"customer": "Acme"})

# Upload to S3
result = client.render("invoice", {"customer": "Acme"}, s3={
    "bucket": "my-bucket",
    "key": "invoices/001.pdf",
    "accessKeyId": "AK...",
    "secretAccessKey": "SK...",
})
print(result["url"])

client.render_async(slug, data=None, *, webhook_url=None)

Start an asynchronous render job. Returns {"jobId": "...", "status": "pending"}.

job = client.render_async("report", data, webhook_url="https://example.com/hook")
print(job["jobId"])

client.get_job(job_id)

Poll the status of an async job.

result = client.get_job("job-123")
if result["status"] == "complete":
    pdf_b64 = result["pdfBase64"]

client.extract(pdf_bytes)

Extract embedded data from a PDF. Returns the data dict, or None if none is embedded.

data = client.extract(pdf_bytes)

Error Handling

All methods raise FormeError on non-2xx responses:

from formepdf import Forme, FormeError

try:
    pdf = client.render("invoice", data)
except FormeError as e:
    print(f"Error {e.status}: {e.message}")

Requirements

  • Python 3.8+
  • No dependencies (stdlib only)

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

formepdf-0.8.1.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

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

formepdf-0.8.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file formepdf-0.8.1.tar.gz.

File metadata

  • Download URL: formepdf-0.8.1.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.12

File hashes

Hashes for formepdf-0.8.1.tar.gz
Algorithm Hash digest
SHA256 72bce352443d387a11bb30f30acdcf24f17fd7bc03bfd6d84a0f5d23a9ba3be8
MD5 e4fa01e6dea2b81ab435b2425db12735
BLAKE2b-256 c93240b4fc27c849bd4234bdd31d714f77963d0a911ea7f8e4b95da3206590bf

See more details on using hashes here.

File details

Details for the file formepdf-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: formepdf-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.12

File hashes

Hashes for formepdf-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c434b45b7b4b32b5b9e18e022f1a848f95d294107c9627be80b26ed59b761e0b
MD5 60eb7b36f0d2f72bb60e090da2611da9
BLAKE2b-256 e80298491ead31d3e50e57d6bfcf4c9110ac336d36d0125213bc0bb48d35e557

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