Skip to main content

A Python SDK for PDF Craft API

Project description

PDF Craft SDK

A Python SDK for interacting with the PDF Craft API. It simplifies the process of converting PDFs to Markdown or EPUB by handling authentication, task submission, and result polling.

Installation

You can install the package from PyPI:

pip install pdf-craft-sdk

Usage

Basic Usage

The SDK provides a high-level convert method that handles everything for you (submission + polling).

from pdf_craft_sdk import PDFCraftClient, FormatType

# Initialize the client
client = PDFCraftClient(api_key="YOUR_API_KEY")

# Convert a PDF to Markdown and wait for the result
try:
    pdf_url = "cache://your-pdf-file.pdf"
    download_url = client.convert(pdf_url, format_type=FormatType.MARKDOWN)
    print(f"Conversion successful! Download URL: {download_url}")
except Exception as e:
    print(f"An error occurred: {e}")

Advanced Usage

If you prefer to handle the steps manually or asynchronously:

from pdf_craft_sdk import PDFCraftClient, FormatType

client = PDFCraftClient(api_key="YOUR_API_KEY")

# 1. Submit task
task_id = client.submit_conversion(
    pdf_url="cache://your-pdf-file.pdf",
    format_type=FormatType.MARKDOWN
)
print(f"Task submitted. ID: {task_id}")

# 2. Wait for completion explicitly
try:
    download_url = client.wait_for_completion(task_id, format_type=FormatType.MARKDOWN)
    print(f"Download URL: {download_url}")
except Exception as e:
    print(f"Conversion failed or timed out: {e}")

Configuration

The convert and wait_for_completion methods accept optional configuration for polling behavior:

  • max_wait_ms: Maximum time (in milliseconds) to wait for the conversion. Default is 7200000 (2 hours).
  • check_interval_ms: Initial polling interval (in milliseconds). Default is 1000 (1 second).
  • max_check_interval_ms: Maximum polling interval (in milliseconds). Default is 5000 (5 seconds).
  • backoff_factor: Multiplier for increasing interval after each check, or PollingStrategy enum. Default is PollingStrategy.EXPONENTIAL (1.5).

Polling Strategies

You can use PollingStrategy enum for backoff_factor:

  • PollingStrategy.EXPONENTIAL (1.5): Default. Starts fast, slows down.
  • PollingStrategy.FIXED (1.0): Polls at a fixed interval.
  • PollingStrategy.AGGRESSIVE (2.0): Doubles the interval each time.
from pdf_craft_sdk import PollingStrategy

# Example: Stable Polling (Every 3 seconds)
download_url = client.convert(
    pdf_url="...", 
    check_interval_ms=3000,
    max_check_interval_ms=3000,
    backoff_factor=PollingStrategy.FIXED
)

# Example: Long Running Task (Start slow, check infrequently)
download_url = client.convert(
    pdf_url="...", 
    check_interval_ms=5000,
    max_check_interval_ms=60000, # 1 minute
    backoff_factor=2.0 # or PollingStrategy.AGGRESSIVE
)

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

pdf_craft_sdk-0.4.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

pdf_craft_sdk-0.4.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pdf_craft_sdk-0.4.1.tar.gz.

File metadata

  • Download URL: pdf_craft_sdk-0.4.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for pdf_craft_sdk-0.4.1.tar.gz
Algorithm Hash digest
SHA256 82932b55be420293bed21f7dc4a617eccf34d888be4aa9f060712797b4f756c1
MD5 8ae20b399229078a1f8483d8eac74c76
BLAKE2b-256 a9ddd35eed13468562bfeec2161483bc556d43c1cd84f3c1796376fa98598191

See more details on using hashes here.

File details

Details for the file pdf_craft_sdk-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: pdf_craft_sdk-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for pdf_craft_sdk-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3a0236c73bbf2d492ec3e5be32e13cadf74d3b736519e154ebeaf463eb742804
MD5 bf1469bfbea5425cecd7ced33038bf24
BLAKE2b-256 7f3f06f6a2b060c362ef6d9b4bb68a073b2667cefb08c856c4172b6ec9633c4e

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