1. Products
  2.   Editor
  3.   Python
  4.   python-docx
 
  

Open Source Python DOCX Editor Library

Free & Open Source Python library to create and edit DOCX documents.

What is python-docx?

Python-docx is an open-source Python library to create, open and modify Microsoft Word DOCX files. It provides an easy to use document object model to work with the DOCX files. You can use the API in your python applications to create text, paragraphs, images, tables, etc. and the python-docx will manage the rest for you.

Python-docx Features

Following are some of the main features of python-docx:

  • Creating DOCX Files: Python-docx lets you create DOCX files from scratch. You can literally create an empty document and save it as it is in the DOCX file format.
  • Edit DOCX Files: Python-docx lets you open existing DOCX files, edit its contents and save the updated document back to the disc. You have access to the
  • Adding Tables: Python-docx enables you to easily, design and insert tables into your DOCX files, making displaying tabular data and maintaining a structured layout simple.
  • Adding Images: Python-docx allows for including images in your DOCX documents, making it possible to incorporate logos, graphics, or photographs to enhance visual appeal.
GitHub

GitHub Stats

Name:
Language:
Stars:
Forks:
License:
Repository was last updated at

Getting Started with python-docx

We can download the python-docx library from GitHub or using pip install command:

Installation

Installing python-docx is simple and can be done from terminal as shown below:

Installing python-docx


pip3 install python-docx

Create DOCX Document in Python

You can create a blank DOCX document using the python-docx library's Document class. It can then be saved to disc as DOCX file in the Microsoft Word's 2007+ format as shown in below example:

Open an Existing DOCX File with Python

With Python-docx library, you can also load an existing DOCX file, make changes to it and then save it back with a new name. This is similar to the "Save As" option available in Microsoft Word.

Insert Picture in DOCX Document with Python-docx

Python-docx lets you create word documents and insert images into it with simple code. You can also change the size of the image while adding to the document. The default size of image is 300x300 pixels with 300 dpi.

Add Table to DOCX file in Python

Microsoft Word lets you insert table in a document. A table comprises of rows and columns. The cross-section of a rown and column is called a cell. You can insert text as well as images in each cell.

Conclusion

Python-docx has offers lots of features to create and enrich a Word document from scratch. It is easy to use, has simplified syntax and fast.

Similar Products

 English