How to convert an ODT File to DOCX in Python

Cloudmersive
2 min readJun 26, 2020

I’m just going to come out and say it. Nobody wants to deal with converting between file formats, am I right? Setting up such a solution in Python can be particularly aggravating, so what do you say we skip it completely? To do this, we will need a pre-made solution, and in this case we are making use of an API to get the job done. This is going to be incredibly easy, so let’s get started.

Use pip install to bring our client into the project.

pip install cloudmersive-convert-api-client

Now that the API is accessible, we can call convert_document_odt_to_docx, which will handle our conversion.

from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom cloudmersive_convert_api_client.rest import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_convert_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_convert_api_client.ConvertDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))input_file = '/path/to/file' # file | Input file to perform the operation on.try:# Convert Office Open Document ODT to Word DOCXapi_response = api_instance.convert_document_odt_to_docx(input_file)pprint(api_response)except ApiException as e:print("Exception when calling ConvertDocumentApi->convert_document_odt_to_docx: %s\n" % e)

And you are officially done. You’re welcome!

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.