Registry / data / convertapi

convertapi

JSON →
library2.0.0pypypi✓ verified 86d ago

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.

pip install convertapi
INSTALL
IMPORT
SIG · CONVERTAPI
C
convertapi
datapythonv2.0.0
Install
2.1s avg
Import
619ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.659s · 21.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.1s · import 0.578s · 22MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

convertapi
import convertapi
from convertapi import ConvertApi
The primary interface is directly through the `convertapi` module, not a class named `ConvertApi`.

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}")
Debug
Known issues
breakingVersion 2.0.0 switches to using an 'Authorization' header for API authentication instead of query parameters. Older versions (pre-v2.0.0) might have implicitly or explicitly used query parameters.
fix
Ensure your client library is updated to v2.0.0 or later. No explicit code change is usually required if you set `convertapi.api_secret`, as the library handles the header internally.
affects: < 2.0.0
breakingVersion 2.0.0 removes support for 'alternative converters'. If your application relied on specific, non-default conversion engines, those options are no longer available.
fix
Review your conversion calls and remove any parameters that specified an 'alternative converter'. Test existing conversions thoroughly as the default converter might behave differently or lack certain features.
affects: < 2.0.0
gotchaIn v2.0.0, default upload and download timeouts were changed from a fixed value (e.g., 1800 seconds in v1.5.0) to `None`. This means operations will now effectively have no client-side timeout unless explicitly configured, potentially leading to processes hanging indefinitely for very long conversions or network issues.
fix
For critical operations, consider explicitly setting timeouts. You can configure `convertapi.default_timeout` or pass `timeout` parameter to `convertapi.convert` for individual calls.
affects: >= 2.0.0
gotchaThe `File` parameter in `convertapi.convert` can accept various types (local path string, URL string, or bytes-like object). Mismatching the format (e.g., providing a URL for a file expected locally) can lead to conversion errors.
fix
Always ensure the value passed to the `File` parameter matches the expected input type for your specific conversion scenario. For local files, ensure the path is accessible; for URLs, ensure it's a valid and publicly accessible link.
affects: All versions
Errors
Common errors & fixes
convertapi.client.ConvertApiError: Unauthorized. Check your API secret.
The API secret is either missing, incorrect, or expired. The ConvertAPI service rejected the request.
fix
Double-check your `convertapi.api_secret` value. Ensure it matches the secret found on your ConvertAPI dashboard (https://www.convertapi.com/a/dashboard). Make sure environment variable `CONVERTAPI_SECRET` is set if you are loading it from there.
AttributeError: module 'convertapi' has no attribute 'secret' (or 'api_key')
Attempting to set the API secret using an incorrect attribute name.
fix
The correct attribute to set the API secret is `convertapi.api_secret`. Change `convertapi.secret = '...'` or `convertapi.api_key = '...'` to `convertapi.api_secret = '...'`.
convertapi.client.ConvertApiError: The 'File' parameter is required.
The input file for conversion was not provided in the `parameters` dictionary when calling `convertapi.convert()`.
fix
Ensure that the `parameters` dictionary passed to `convertapi.convert()` includes a key named 'File' with the path, URL, or bytes of the file you intend to convert, e.g., `{'File': 'path/to/file.docx'}`.
Upgrade
Version history
2.0.0latest on PyPI · released Sep 14, 2024
Audit
Dependencies
requestsrequiredUsed for making HTTP requests to the ConvertAPI service.
urllib3requiredHTTP client library, a dependency of requests.
Agent activity
18 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
convertapi — pip install convertapi · libregistry