Document Conversion Library for Python

The ConvertAPI Python library streamlines document conversion and manipulation tasks directly within your Python environment. With support for a wide range of file formats, you can easily convert, merge, compress, and redact PDFs, images, Office documents, and more.

PyPi GitHub

Integrate within minutes

It is easy to start converting documents using Python in a few simple steps:

1

Sign up for a free account

Sign up for free and receive 250 conversions to try and evaluate our service. You will receive a free trial with no credit card required upon registration!

2

Set up the conversion online

On your account dashboard you will access an intuitive UI tool that allows you to set up the conversion, adjust the parameters, and try the conversion online with zero code.

3

Copy auto-generated code snippet

Once you have set up the conversion parameters and are happy with the conversion results, you will receive an auto-generated Python code snippet with your custom parameters!

Get started now

Document management toolkit for Python

The ConvertAPI Python library simplifies integrating advanced document transformation and management functionalities into your Python projects. It supports hundreds of file formats, enabling you to efficiently convert, merge, compress, and securely redact PDFs, Office documents, images, and beyond. Designed for clarity and flexibility, its user-friendly API ensures you spend less time wrestling with complex operations and more time enhancing your application’s features.

File Converter Suite

High-performance and unbeatable accuracy document converter suite with support for over 500+ conversion.

Document Builder using Python

Generate dynamic DOCX and PDF documents like invoices, contracts, reports, on the fly.

Document Management tools

Protect, redact, compare, watermark, flatten, compress and modify your documents using ConvertAPI Python SDK.

Security and Decryption

Protect and unprotect PDFs, MS Office Powerpoint and MS Office Word documents.

AI Data Extractor

Built to scale with your business, whether you're handling a few conversions or thousands.

Archiving & Optimization

Reduce file sizes without losing quality. Archive converters are designed to handle over 100 different file formats.

Take a look at Python code samples

View on GitHub

Configure it online - we will generate the Python code for you!

Configure your file conversion directly online using our intuitive interface. Select the desired parameters and see the results in real-time. Once you're satisfied, we’ll automatically generate the Python code for you, making integration into your project effortless. No need to start from scratch - just copy the code and implement it seamlessly into your Python application!

Get started now

File conversion example using Python

The ConvertAPI Python library offers developers a straightforward way to integrate advanced file conversion and document handling features into their Python applications. With support for a vast range of formats, covering PDFs, Office documents, images, and beyond - it simplifies complex operations such as merging files, compressing large datasets, extracting critical information, and securely removing sensitive content.

Install the ConvertAPI Python library into your project

To get started, install the ConvertAPI Python package using PyPi:

pip install --upgrade convertapi

Convert PDF to TXT example

The ConvertAPI Python library simplifies extracting readable text from your PDF files, making it effortless to work with document data in your Python projects. Whether you’re building search indexes, performing text analysis, or integrating content into other systems, the library provides straightforward methods to transform PDFs into text with just a few lines of code. Its flexible parameters and broad format support ensure that you gain quick, accurate access to the underlying text, freeing you from the complexity of manual extraction and letting you focus on delivering value through your application’s features.

Here is an example of text extraction from a PDF document using Python:

// Code snippet is using the ConvertAPI JavaScript Client: https://github.com/ConvertAPI/convertapi-library-js

// Code snippet is using the ConvertAPI Node.js Client: https://github.com/ConvertAPI/convertapi-nodejs

// Code snippet is using the ConvertAPI PHP Client: https://github.com/ConvertAPI/convertapi-php

// Code snippet is using the ConvertAPI Java Client: https://github.com/ConvertAPI/convertapi-java

// Code snippet is using the ConvertAPI C# Client: https://github.com/ConvertAPI/convertapi-dotnet

# Code snippet is using the ConvertAPI Ruby Client: https://github.com/ConvertAPI/convertapi-ruby

# Code snippet is using the ConvertAPI Python Client: https://github.com/ConvertAPI/convertapi-python

// Code snippet is using the ConvertAPI Go Client: https://github.com/ConvertAPI/convertapi-go

REM Code snippet is using the command line utility program: https://github.com/ConvertAPI/convertapi-cli

<!-- For conversions with the multiple file result please refer to this example: https://repl.it/@ConvertAPI/HTML-Form-with-multiple-file-result -->

Convert File Stream

This example demonstrates converting text content directly from memory into a PDF, eliminating the need for intermediate file storage. It is ideal for applications that generate content dynamically and require immediate conversion without disk I/O.

Key Features:

  • Utilizes UploadIO to handle in-memory text data.
  • Performs conversion to PDF format.
  • Saves the resulting PDF to a temporary directory.
convertapi.api_credentials = os.environ['CONVERT_API_TOKEN'] # your api token

# Example of using content stream to convert to pdf
# https://www.convertapi.com/txt-to-pdf

content = "Test content string"
upload_io = convertapi.UploadIO(content, 'test.txt')
result = convertapi.convert('pdf', { 'File': upload_io })
saved_files = result.save_files(tempfile.gettempdir())

print("The PDF saved to %s" % saved_files)

Convert URL to PDF

Illustrates how to convert a live web page into a PDF by providing its URL, facilitating the capture of web content in a portable format. It's useful for archiving web pages or generating PDF versions of online content for offline access or record-keeping.

  • Accepts a web page URL as input.
  • Converts the web page to a PDF document.
  • Stores the PDF in a specified directory.
convertapi.api_credentials = os.environ['CONVERT_API_TOKEN'] # your api token

# Example of converting Web Page URL to PDF file
# https://www.convertapi.com/web-to-pdf

result = convertapi.convert(
    'pdf',
    {
        'Url': 'https://en.wikipedia.org/wiki/Data_conversion',
        'FileName': 'web-example',
    },
    from_format = 'web',
    timeout = 180,
)

saved_files = result.save_files(tempfile.gettempdir())

print("The web page PDF saved to %s" % saved_files)

Conversion chaining (workflow)

Below you will find an example that demonstrates a multi-step conversion process, such as converting a DOCX file to PDF and then compressing the PDF, showcasing how to chain multiple conversions seamlessly. It is meant for complex workflows requiring multiple file transformations in a specific sequence.

Key Features:

  • Performs sequential conversions using intermediate results.
  • Manages multiple steps within a single process.
  • Outputs the final converted file after all transformations.
convertapi.api_credentials = os.environ['CONVERT_API_TOKEN'] # your api token

# Short example of conversions chaining, the PDF pages extracted and saved as separated JPGs and then ZIP'ed
# https://www.convertapi.com/doc/chaining

print('Converting PDF to JPG and compressing result files with ZIP')

jpg_result = convertapi.convert('jpg', { 'File': 'files/test.pdf' })

print("Conversions done. Cost: %s. Total files created: %s" % (jpg_result.conversion_cost, len(jpg_result.files)))

zip_result = convertapi.convert('zip', { 'Files': jpg_result.files })

print("Conversions done. Cost: %s. Total files created: %s" % (zip_result.conversion_cost, len(zip_result.files)))

saved_files = zip_result.save_files(tempfile.gettempdir())

print("File saved to %s" % saved_files)

Retrieve user information

The final example illustrates how to retrieve account information, such as usage statistics and remaining conversion credits, using the ConvertAPI Python library. It is important for monitoring account usage and managing conversion quotas programmatically.

convertapi.api_credentials = os.environ['CONVERT_API_TOKEN'] # your api token

# Retrieve user information
# https://www.convertapi.com/doc/user

print(convertapi.user())

With our Python SDK, you can seamlessly access more than 500+ converters and document handling features, all within one cohesive platform.

Whether you supply documents by URL, file stream, or local file path, integrating them into your current setup is effortless. For even better performance, consider setting up conversion workflows, allowing you to handle several operations at once and streamline the entire process.

For detailed guidance and advanced best practices, don’t forget to check out our GitHub repository.

Automate Your Document Management using Python

Take control of your documents with our Python document management SDK. From basic conversions to full workflow automation, we provide the expertise and tools you need to manage your documents efficiently.

Data security is our top priority

We ensure that all document processing is handled securely in the cloud, adhering to industry-leading standards like ISO 27001, GDPR, and HIPAA. To enhance security even further, we can ensure that no files or data are stored on our servers and never leave your country.

Learn more about security

Businesses trust us

Highest rated File Conversion API on major B2B software listing platforms: Capterra, G2, and Trustpilot.

"ConvertAPI has been a game-changer for our document automation workflows. Their conversion accuracy and API reliability are unmatched in the industry for over 7 years."

"ConvertAPI is a reliable, cost-effective solution with a proven track record of stability. It has grown significantly in maturity, adopting enterprise-grade practices over the years."

"We've integrated ConvertAPI across our entire document processing platform. The performance is exceptional and the support team is always responsive. Highly recommended!"

Frequently asked questions

What is the ConvertAPI Python library used for?

The ConvertAPI Python library allows you to incorporate document conversion, manipulation, and management features directly into your Python applications. It supports a vast range of file formats, making it easy to convert PDFs, Office documents, images, and more with minimal code.

Which file formats can I convert with this library?

The library supports over 500+ file formats, including PDFs, Word documents, Excel spreadsheets, PowerPoint presentations, images, and more. This versatility makes it a one-stop solution for diverse document processing tasks.

How do I install the ConvertAPI Python library?

You can install it via pip. Simply run: pip install convertapi. After installing, import it into your Python script and start converting documents right away.

Can I customize the conversion process?

Absolutely. The ConvertAPI Python library lets you specify parameters such as image quality, page ranges, metadata handling, and more. This gives you the flexibility to produce the exact output you need.

Does it handle large files and batch operations?

Yes. The library is designed to work efficiently with large documents, and you can set up workflows to batch process multiple files. This helps maintain smooth performance and reduce manual effort in high-volume scenarios.

How do I ensure the security of my data?

ConvertAPI follows strict security and compliance standards. You can process files without persistent storage or work directly in memory to minimize data exposure. For more details, refer to the official documentation and Privacy Policy.

Where can I find more examples and support?

Visit our GitHub repository for detailed code samples, best practices, and advanced usage patterns. For personalized assistance, our support team is ready to help you address any questions or challenges.

Try our Python library for free!