Skip to main content

HandleMyFile for Python

PyPI Version Python Versions License: MIT

Edge-native, high-precision PDF to DOCX converter engine in pure Rust with native PyO3 bindings.
Zero external Java, LibreOffice, or Poppler dependencies. Zero cloud egress.


Why HandleMyFile for Python?

Most Python PDF-to-Word solutions suffer from critical operational drawbacks:

  • They wrap heavy external applications like LibreOffice / soffice or Java runtimes, causing massive container bloat (500 MB+ Docker images) and high memory overhead.
  • Or they rely on third-party SaaS cloud APIs, introducing data privacy risks, network latency, and recurring billing.

HandleMyFile embeds a pure Rust Document Layout Analysis (DLA) engine directly into Python as a native C-extension:

  1. Zero External Binary Dependencies:
    No apt-get install libreoffice, no Java JVM, no Poppler utilities. Just pip install handlemyfile.
  2. Lightning-Fast Native PyO3 Execution:
    Executes directly in-process at native compiled speed with minimal RAM consumption.
  3. Versatile Dual API (Bytes & Files):
    Supports in-memory byte streaming convert(pdf_bytes) for high-throughput web frameworks (FastAPI, Flask, Django) as well as file-to-file conversion convert_file(in_path, out_path) for batch jobs.
  4. Clean OOXML Structure:
    Generates validated OpenXML Word documents with real paragraph hierarchies, styled headings, true tables (<w:tbl>), and dynamic page numbers (<w:fldSimple w:instr="PAGE"/>).

Honest & Transparent Limitations


Installation

pip install handlemyfile

Usage

1. File-to-File Conversion

import handlemyfile

# Simple 1-line conversion:
handlemyfile.convert_file("document.pdf", "output.docx")

# With real-time page progress callback:
def on_progress(current_page, total_pages, stage):
    print(f"Processing page {current_page}/{total_pages} [{stage}]")

handlemyfile.convert_file("large_document.pdf", "output.docx", on_progress=on_progress)

2. In-Memory Streaming (FastAPI / Flask Example)

Perfect for serverless functions, microservices, or web APIs where files shouldn't touch the disk:

from fastapi import FastAPI, UploadFile, Response
import handlemyfile

app = FastAPI()

@app.post("/convert")
async def convert_pdf(file: UploadFile):
    pdf_bytes = await file.read()
    
    # 100% in-memory conversion:
    docx_bytes = handlemyfile.convert(pdf_bytes)
    
    return Response(
        content=docx_bytes,
        media_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
        headers={"Content-Disposition": f"attachment; filename={file.filename.replace('.pdf', '.docx')}"}
    )

3. Granular Typed Exceptions

Handle protected or corrupted files gracefully:

import handlemyfile

try:
    with open("secret_report.pdf", "rb") as f:
        docx_bytes = handlemyfile.convert(f.read())
except handlemyfile.PasswordProtectedError:
    print("Error: This PDF is encrypted or password-protected.")
except handlemyfile.InvalidPdfError:
    print("Error: The file is not a valid PDF document.")
except handlemyfile.CorruptPdfError as e:
    print(f"Error: Corrupted PDF stream: {e}")
except handlemyfile.EmptyDocumentError:
    print("Error: The document contains zero readable pages.")
except handlemyfile.HandleMyFileError as e:
    print(f"Conversion failed: {e}")

4. Standalone CLI

Installing via pip also provides a direct command-line tool:

handlemyfile input.pdf output.docx

License

MIT © HandleMyFile Contributors

Metadata

Release files for handlemyfile 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for handlemyfile 0.2.1
File Size Uploaded Provenance Actions
handlemyfile-0.2.1.tar.gz 179.1 kB Without provenance Details for handlemyfile-0.2.1.tar.gz

Release files / handlemyfile-0.2.1.tar.gz

Download URL handlemyfile-0.2.1.tar.gz
Size 179.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e626423a15a423753ddc7d531b1a2b632f0c97dfd52a9ea8bd88b6d41944e31e
BLAKE2b-256 checksum
How to use checksums
dc5c18c0762fd5e9caa979e8c248abfc26481303076efe2f41845b215dd57658
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Security for handlemyfile 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page