Skip to main content

Introduction

The docx module creates, reads and writes Microsoft Office Word 2007 docx files.

These are referred to as ‘WordML’, ‘Office Open XML’ and ‘Open XML’ by Microsoft.

These documents can be opened in Microsoft Office 2007 / 2010, Microsoft Mac Office 2008, Google Docs, OpenOffice.org 3, and Apple iWork 08.

They also validate as well formed XML.

The module was created when I was looking for a Python support for MS Word .docx files, but could only find various hacks involving COM automation, calling .Net or Java, or automating OpenOffice or MS Office.

The docx module has the following features:

Making documents

Features for making documents include:

  • Paragraphs

  • Bullets

  • Numbered lists

  • Document properties (author, company, etc)

  • Multiple levels of headings

  • Tables

  • Section and page breaks

  • Images

http://github.com/mikemaccana/python-docx/raw/master/screenshot.png

Editing documents

Thanks to the awesomeness of the lxml module, we can:

  • Search and replace

  • Extract plain text of document

  • Add and delete items anywhere within the document

  • Change document properties

  • Run xpath queries against particular locations in the document - useful for retrieving data from user-completed templates.

Getting started

Making and Modifying Documents

  • Just download python docx.

  • Use pip or easy_install to fetch the lxml and PIL modules.

  • Then run:

    example-makedocument.py

Congratulations, you just made and then modified a Word document!

Extracting Text from a Document

If you just want to extract the text from a Word file, run:

example-extracttext.py 'Some word file.docx' 'new file.txt'

Ideas & To Do List

  • Further improvements to image handling

  • Document health checks

  • Egg

  • Markdown conversion support

We love forks, changes and pull requests!

  • Check out the [HACKING](HACKING.markdown) to add your own changes!

  • For this project on github

  • Send a pull request via github and we’ll add your changes!

Want to talk? Need help?

Email python-docx@googlegroups.com

License

Licensed under the MIT license

Short version: this code is copyrighted to me (Mike MacCana), I give you permission to do what you want with it except remove my name from the credits. See the LICENSE file for specific terms.

Release files for docx 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docx 0.2.4
File Size Uploaded
docx-0.2.4.tar.gz 54.9 kB Details

Release files / docx-0.2.4.tar.gz

Download URL docx-0.2.4.tar.gz
Size 54.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9d7595eac6e86cda0b7136a2995318d039c1f3eaa368a3300805abbbe5dc8877
BLAKE2b-256 checksum
How to use checksums
4a8e5a01644697b03016de339ef444cfff28367f92984dc74eddaab1ed60eada
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.4 This release

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page