ConvertAPI Python Client

2.0.0 · active · verified Thu Apr 16

The `convertapi` Python Client provides an interface to ConvertAPI's file conversion and manipulation services. It allows users to convert documents, images, videos, and more between various formats programmatically. The current version is 2.0.0, and the library is actively maintained with releases addressing features and breaking changes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the ConvertAPI client with your API secret and perform a simple file conversion from a URL. It converts a DOC file to PDF and saves the output locally. Error handling for API-specific and general exceptions is included.

import os
import convertapi

# Get your API secret from https://www.convertapi.com/a/dashboard
# It's highly recommended to use environment variables for secrets.
convertapi.api_secret = os.environ.get('CONVERTAPI_SECRET', 'YOUR_CONVERTAPI_SECRET')

try:
    # Example: Convert a Word document (DOC) to PDF
    # The 'File' parameter can be a local path, URL, or bytes.
    result = convertapi.convert('pdf', {
        'File': 'https://cdn.convertapi.com/example.doc' # Example URL
    }, from_format='doc')

    # Save the resulting files (e.g., to the current directory)
    result.save_files('./')
    print("Conversion successful! Files saved.")

except convertapi.client.ConvertApiError as e:
    print(f"Conversion failed: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →