Tutorials

How to Integrate ComPDFKit API Library in Python

By ComPDFKit | Mon. 15 Jul. 2024
PDF APIPython

ComPDFKit allows Python developers to build a PDF application by merely calling the Python API Library. With this approach, developers eliminate the need for extensive research and design of PDF functionalities and quickly integrate various services and features into their applications, ultimately enhancing the user experience.

Therefore, in this tutorial, we will show you how to integrate ComPDFKit API Library in Python step by step, including Authentication, Python API Library installation, making API Library requests, etc.

Before you start, you can register a ComPDFKit API Libraries free account to get unlimited free processing of 1,000 documents within 30 days.

 


 

Windows   Web   Android   iOS   Mac   Server   React Native   Flutter   Electron
30-day Free

 

Requirements Before API Library Python Calling

Programming Environment: Python 3.8 and higher

Dependencies: pip.

 

Step 1: Register and Get a License

- Please register a ComPDFKit account as a developer, and then you can obtain a free account so that unlimitedly process 1,000 documents for free every month

- Access the Project ID, Public key, and Secret Key by going to the console’s API Dashboard>Project>API Keys.

 

 

Step 2: Obtain the Dependencies of the ComPDFKit Python API Library

Install the ComPDFKit Python API Library via the Dependencies. As well as, run the following command:

pip install compdfkit-api-python

 

Step 3: Authentication Your License

ComPDFKit API uses the JSON Web Tokens method for secure authentication. You can authenticate your project as easily as this:

# Create a client
client = CPDFClient(public_key, secret_key)

To learn more about this method and its applications, please take a look at the Authentication section in our API reference.

 

Step 4: Make API Requests

1. The Request Workflow for API Library Python:

It’s very easy to make the API Library request. Usually, it consists of the following 4 steps:  

- Create a task

- Upload a file

- Execute a task

- Download a result file

Note:

1. Different PDF APIs correspond to different tasks, so please determine the PDF features of the PDF API you need when creating a task.

2. Be mindful of the file formats you upload. While most ComPDFKit PDF APIs are designed to process PDF files, some Conversion PDF APIs can handle different formats, such as CSV for the CSV to PDF API.

 

2. Sample: Convert PDF to Excel by Integrating Python API Libraries

Before building your Python API request, please provide the public key and secret key as illustrated in the following code example.

# Create a client
client = CPDFClient(public_key, secret_key)

# Create a task
# Create an example of a PDF tO Word task
create_task_result = client.create_task(CPDFConversionEnum.PDF_TO_WORD)

# Get a task id
task_id = create_task_result.task_id

# Upload files
client.upload_file(convert_file, task_id)

# Execute task
client.execute_task(task_id)

# Query TaskInfo
task_info = client.get_task_info(task_id)

By integrating API Library Python like ComPDFKit, enterprises can simplify PDF-related workflows, improve productivity, reduce the costs of errors and debugging, maintain data security, and offer better user experience for employees and customers.

 

Final Words

In this tutorial, we have introduced step by step how to integrate the ComPDFKit API library in Python. With the comprehensive and free PDF API library provided by ComPDFKit, you can easily find the corresponding PDF API integration guide on the ComPDFKit's PDF API library documentation page to quickly improve your user experience.

 

ComPDFKit API has a professional R&D team dedicated to producing comprehensive technical documents and guides to help developers.

 

Therefore, if you have any questions or questions, please contact us and you will get a timely response.

Windows   Web   Android   iOS   Mac   Server   React Native   Flutter   Electron
30-day Free