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.3.0.tar.gz (4.4 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.3.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdf_craft_sdk-0.3.0.tar.gz
  • Upload date:
  • Size: 4.4 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.3.0.tar.gz
Algorithm Hash digest
SHA256 4b42780be478d5c0333f565eee58a05daf1c1e90a9aa5e121fdef781f077c4a7
MD5 3d0dba14325d882e4a82bef452a15a67
BLAKE2b-256 de4b78d8c90fae75f8603c34ea3bada0d4b906a2500a6788cde6f4eff5ca4026

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdf_craft_sdk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68b2f38f48bc3186a2eca6c23f2be422accb0c15aa80fdc1082adc4a65dff5e0
MD5 529a6889739f4a26590eae6f98cc9eb4
BLAKE2b-256 f6f69130346c28e584c818afef2369ab76a857807537b6710c3c18a674b87ae6

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