Skip to main content
GuidePython

PDF to Word API Example in Python

Learn how to convert PDF to Word (DOCX) using the Convert Fleet REST API in Python with the requests library. Includes complete code examples.

LanguagePython
Conversionpdfdocx
API ReferenceView Endpoint →

You need an API key to follow this guide. Get a free API key →

1Install the requests Library

Install the requests package if you haven't already.

bash
pip install requests

2Get Your API Key

Sign up at convertfleet.com and generate a free API key from your dashboard.

3Convert PDF to Word in Python

Use the following Python script to convert a PDF file to a Word document using the Convert Fleet API.

python
import requests

def convert_pdf_to_word(input_path: str, output_path: str):
    url = "https://convertfleet.com/api/convert"
    headers = {"Authorization": "Bearer YOUR_API_KEY"}

    with open(input_path, "rb") as f:
        files = {"file": f}
        data = {"to": "docx"}
        response = requests.post(url, files=files, data=data, headers=headers)

    if response.status_code == 200:
        with open(output_path, "wb") as out:
            out.write(response.content)
        print("Conversion successful!")
    elif response.status_code == 401:
        raise Exception("Invalid API key.")
    elif response.status_code == 429:
        raise Exception("Rate limit exceeded. Upgrade to Pro.")
    else:
        raise Exception(f"Conversion failed: {response.status_code}")

convert_pdf_to_word("input.pdf", "output.docx")

That's it!

You've successfully integrated the Convert Fleet API. Check the API reference for the full list of parameters and error codes.

Related API Endpoints

More Integration Guides

Start Building Today

Free tier includes 200 free credits (valid 30 days from signup). Pro plan unlocks unlimited API access.