← Back to pdf2epub

Convert PDF to EPUB3 Programmatically with Python (Free API)

If you're building a document pipeline, a publishing platform, or any workflow where PDFs need to become EPUBs at scale, doing it by hand is not an option. The toolkit.bot PDF-to-EPUB API lets you automate the conversion with a single HTTP request — no browser, no UI, just code.

When You Need Batch PDF-to-EPUB Conversion

The Endpoint

Python Example: Single File Conversion

Install requests if you haven't already (pip install requests), then:

import requests

INPUT_PDF = "manuscript.pdf"
OUTPUT_EPUB = "manuscript.epub"

with open(INPUT_PDF, "rb") as pdf_file:
    response = requests.post(
        "https://toolkit.bot/convert",
        files={"file": (INPUT_PDF, pdf_file, "application/pdf")},
    )

response.raise_for_status()

with open(OUTPUT_EPUB, "wb") as epub_file:
    epub_file.write(response.content)

print(f"Saved {len(response.content):,} bytes to {OUTPUT_EPUB}")

That's it. response.content is the raw bytes of a valid EPUB3 file.

curl Example

No Python environment? You can convert any PDF straight from the terminal:

curl -X POST https://toolkit.bot/convert   -F 'file=@document.pdf'   -o document.epub

The -F flag sends the file as multipart/form-data and -o writes the EPUB response body directly to disk. On success, document.epub is a valid EPUB3 file.

Python Example: Batch Conversion

Converting a directory of PDFs:

import requests
from pathlib import Path

INPUT_DIR = Path("pdfs/")
OUTPUT_DIR = Path("epubs/")
OUTPUT_DIR.mkdir(exist_ok=True)

session = requests.Session()

for pdf_path in INPUT_DIR.glob("*.pdf"):
    print(f"Converting {pdf_path.name}...")
    with open(pdf_path, "rb") as pdf_file:
        response = session.post(
            "https://toolkit.bot/convert",
            files={"file": (pdf_path.name, pdf_file, "application/pdf")},
        )

    if response.ok:
        output_path = OUTPUT_DIR / pdf_path.with_suffix(".epub").name
        output_path.write_bytes(response.content)
        print(f"  -> Saved to {output_path}")
    else:
        print(f"  -> Error {response.status_code}: {response.text}")

Handling the Response

import time

def convert_pdf(session, pdf_path, retries=3):
    for attempt in range(retries):
        with open(pdf_path, "rb") as f:
            resp = session.post(
                "https://toolkit.bot/convert",
                files={"file": (pdf_path.name, f, "application/pdf")},
            )
        if resp.status_code == 200:
            return resp.content
        if resp.status_code >= 500 and attempt < retries - 1:
            time.sleep(2 ** attempt)
            continue
        resp.raise_for_status()
    raise RuntimeError(f"Failed after {retries} attempts")

Integrating Into a CI/CD Pipeline

If you generate PDFs as a build artifact (from LaTeX, Pandoc, WeasyPrint), add a conversion step that produces EPUBs automatically. A GitHub Actions step:

- name: Convert PDF to EPUB
  run: python scripts/convert_to_epub.py --input dist/output.pdf --output dist/output.epub

OpenAPI Spec

The full API schema is available at toolkit.bot/openapi.json. Import it into Postman, Insomnia, or any OpenAPI-compatible client to explore request/response shapes and generate client stubs for other languages.

Free Tier and Pricing

The toolkit.bot API includes a free tier of 5 conversions per month — no credit card required to get started. For production workloads with higher monthly volumes, see toolkit.bot/pricing.

What the API Produces

Output is valid EPUB3 with UTF-8 encoded text, embedded images extracted from the PDF, EPUB Accessibility 1.1 metadata, and structural navigation from detected headings. The EPUB passes EPUBCheck validation for standard-conformant PDFs.

Try the API with your first five conversions free — no account setup required.

Get Started →