Work with Word Documents in Python

  Python DOCX

Work with Word Documents in Python

Word and PDF documents in Python

Open, generate, edit, split, merge, compare and convert a Word document in Python. It's easy for Python developers to manipulate Microsoft Word documents.
Simply integrate our Cloud API into your applications or Django framework to work with your documents. Use templates to generate documents. We provide a REST API for converting documents in PDF, images and other supported file formats.

While working with documents and files, how many times did you ask Google "How to convert Word documents to text files with Python" or "How to extract data from Word documents using Python"?
How many times did you want to find an easy, free and online tool to help you to create and update Microsoft Word DOCX files?
Our Cloud API for Python will answer all your questions and make working with documents much easier.

  • Main
  • Convert
  • Structure
  • Content
  • Tables
  • MailMerge
  • Other
  • Plugins


Python 2.7 & 3.5

Supported Document Formats

You can both read and write documents in: DOCX, DOC, PDF, MD, RTF, DOCM, DOTX, DOT, DOTM, ODT, OTT, XML, HTML, MHTML, XHTML, TXT.
The write-only formats are: XPS, OpenXPS, PS, JPEG, PNG, BMP, SVG, TIFF, EMF, PCL, EPUB.
The read-only formats are: MOBI, CHM.
For more details, please check Supported File Formats.

What is Cloud Python SDK

Our Cloud API is designed to create, open, edit, split, merge, compare and convert a Word document.
Aspose.Words Cloud Python SDK is a Python library that provides full control of MS Word documents. The library handles all elements of MS Word documents such as text, images, annotations, bookmarks, tables, hyperlinks, shapes, etc. You can execute any operation on these elements by using REST API.

You can work with text, page numbering, headers & footers, paragraphs and other document elements programmatically.
You can use mail merge, modify text, edit footnotes, bookmarks, comments, protect, draw objects and watermarks in DOCX documents with Python.

What Aspose Cloud can do for Python developers

Aspose Cloud provides a powerful file conversion, splitting, merging, editing REST API.
Python developers can easily integrate Python API in their applications or Django framework to handle documents.

Using Python you can edit an existing Word document to correct spellings or add new content to a file. Also, it's used to access and to modify document elements as well as their formatting.

Mail merge and report generation

It allows you to use standard or more complex mail merge operations such as inserting images or repeatable regions in reports.
You can use templates for report generation in Word and then populate documents with XML or JSON data files.

Work with tables in a Word document

You can use the tabular form, lining up with rows and columns.
You can add or delete the table from a Word document to extract the table information from a Word document.

Add watermark to a Word document

It allows you to add/remove any existing watermark in a Word document. For example, you can execute following operations:

  • Add watermark text.
  • Add watermark image.
  • Delete watermark.

Convert PDF to Word in Python

The following code sample shows how to convert PDF to DOCX in the Cloud and save the result to a local file:

Convert PDF to DOCX
from asposewordscloud import WordsApi
from asposewordscloud.models.requests import ConvertDocumentRequest

app_sid = '####-####-####-####-####'
app_key = '##################'
words_api = WordsApi(app_sid, app_key)

with open('sample.pdf', 'rb') as f:
	request = ConvertDocumentRequest(f, format='docx')
	result = words_api.convert_document(request)
print('Output filename: {}'.format(result))

Advanced Features

How to open and edit a DOCX document in Python

  1. Install Python SDK.
  2. Go to the Aspose Cloud Dashboard.
  3. Create a new Account to access all applications and services or Sign In to your existing account.
  4. Click on Applications in the left menu to get Client Id and Client Secret.
  5. Upload a DOCX file to the Cloud Storage or use directly in the request body.
  6. Check Developer Guide to edit a DOCX file in Python.


How to upload a Word document into Aspose Storage?

apiKey = '####'
appSid = '####-####-####-####-####'

# Initialize Aspose.Storage SDK
storage_apiClient = asposestoragecloud.ApiClient.ApiClient(apiKey, appSid, True)
storageApi = StorageApi(storage_apiClient)

# Upload a file to Aspose Cloud Storage
filename = "Sample.docx"
with open(filename, 'rb') as f:
fileData =
storageApi.put_create(filename, fileData)

How to convert docx to pdf with Python?

You can convert a Word document to desired file format in two ways, directly in a request body or convert existing file in the Storage.

# Suppose we have 'Sample.docx' in the Storage
save_options = SaveOptionsData(save_format='pdf', file_name='Sample.pdf', zip_output=True)
request = SaveAsRequest('Empty.docx', save_options)
result = words_api.save_as(request)
print("Result {}".format(result))

How to compare Word documents?

You can try and see the results of comparison using our free online tool.

# Suppose we uploaded 'Sample1.docx' and 'Sample2.docx' into the Storage
# And we want to compare and save results to the file 'Results.docx'
compare_data = CompareData('Sample2.docx', 'author',
request = CompareDocumentRequest('Sample1.docx', compare_data, dest_file_name='Results.docx')
result = words_api.compare_document(request)
print("Result {}".format(result))

How to generate a Word document using Python?

request = CreateDocumentRequest(file_name="Blank.docx")
result = words_api.create_document(request)
print("Result {}".format(result))

Support and Learning Resources