ConvertAPI helps to convert various file formats. Creating PDF and Images from various sources like Word, Excel, Powerpoint, images, web pages or raw HTML codes. Merge, Encrypt, Split, Repair and Decrypt PDF files and many other manipulations. You can integrate it into your application in just a few minutes and use it easily.
Install with pip:
pip install --upgrade convertapi
Install from source with:
pip install .
- Python 3 with
requests; tested on Python 3.10 to 3.14
You can get your API token at https://www.convertapi.com/a/authentication
import convertapi
convertapi.api_credentials = 'api-token'If you need to use a proxy, you can specify it using HTTPS_PROXY environment variable when running your script.
Example:
API_TOKEN=api-token HTTPS_PROXY=https://user:pass@127.0.0.1:9000/ python convert_word_to_pdf_and_png.py
Convert a file to PDF example. All supported file formats and options can be found here.
result = convertapi.convert('pdf', { 'File': '/path/to/my_file.docx' })
# save to file
result.file.save('/path/to/save/file.pdf')Other result operations:
# save all result files to folder
result.save_files('/path/to/save/files')
# get conversion cost
conversion_cost = result.conversion_costresult = convertapi.convert('pdf', { 'File': 'https://website/my_file.docx' })result = convertapi.convert(
'pdf',
{ 'File': '/path/to/my_file' },
from_format = 'docx'
)ConvertAPI accepts additional conversion parameters depending on selected formats. All conversion parameters and explanations can be found here.
result = convertapi.convert(
'pdf',
{
'File': '/path/to/my_file.docx',
'PageRange': '1-10',
'Pdfa': True,
}
)You can always check your usage by fetching user information.
user_info = convertapi.user()
print(user_info['ConversionsTotal'])
print(user_info['ConversionsConsumed'])Set base_uri parameter to use other service domains. Dedicated to the region domain list.
convertapi.base_uri = 'https://eu-v2.convertapi.com/'Find more advanced examples in the /examples folder.
- conversions_chaining.py - Chain two conversions: PDF to JPG images, then the images to a ZIP
- convert_stream.py - Convert text from an in-memory stream to PDF
- convert_url_to_pdf.py - Convert a web page URL to PDF
- convert_word_to_pdf_and_png.py - Convert one Word DOCX file to PDF and to PNG
- create_pdf_thumbnail.py - Turn the first page of a PDF into a JPG thumbnail
- retrieve_user_information.py - Retrieve your ConvertAPI account information
- split_and_merge_pdf.py - Split a PDF and merge its first and last pages into a new PDF
pip install -e . -r test-requirements.txt
pytestTests marked live call the real service and are skipped unless CONVERT_API_SECRET holds an API token
(CONVERT_API_BASE_URI optionally points them at another deployment). Releases are described in
RELEASING.md.
Bug reports and pull requests are welcome on GitHub at https://github.com/ConvertAPI/convertapi-library-python. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The library is available as open source under the terms of the MIT License.