| name | python-docx |
| description | Create and manipulate Microsoft Word documents programmatically. Build reports, contracts, and documentation with full control over paragraphs, tables, headers, styles, and images. |
| version | 1.0.0 |
| category | data |
| type | skill |
| capabilities | ["document_creation","paragraph_formatting","table_generation","header_footer_management","style_customization","image_insertion","template_manipulation","mail_merge_patterns"] |
| tools | ["python","python-docx","lxml"] |
| tags | ["word","docx","document-generation","reports","templates","office-automation"] |
| platforms | ["windows","macos","linux"] |
| related_skills | ["docx-templates","pypdf","openpyxl"] |
| requires | [] |
| scripts_exempt | true |
Python Docx
Overview
Python-docx is a Python library for creating and manipulating Microsoft Word (.docx) documents. This skill covers comprehensive patterns for document automation including:
- Document creation from scratch or templates
- Paragraph formatting with styles, fonts, and alignment
- Table generation with merged cells, styles, and formatting
- Headers and footers with page numbers and dynamic content
- Image insertion with sizing and positioning
- Style management for consistent document appearance
- Template manipulation for document workflows
- Mail merge patterns for bulk document generation
When to Use This Skill
USE when:
- Creating Word documents programmatically from data
- Generating reports with consistent formatting
- Building contracts, invoices, or legal documents
- Automating template-based document creation
- Modifying existing Word documents
- Creating documents with complex table structures
- Generating technical documentation with code blocks
- Building multi-section documents with headers/footers
- Creating documents with embedded images and charts
- Batch processing document generation
DON'T USE when:
- Simple template filling (use docx-templates instead)
- PDF generation is the final output (use pypdf or reportlab)
- Need real-time collaborative editing
- Document requires complex macros or VBA
- Need to preserve complex Word features (use COM automation on Windows)
- Only need to extract text from documents (use python-docx2txt)
Prerequisites
Installation
pip install python-docx
uv pip install python-docx
pip install python-docx Pillow
pip install python-docx Pillow lxml
Verify Installation
from docx import Document
from docx.shared Inches, Pt, Cm
docx.enum.text WD_ALIGN_PARAGRAPH
docx.enum.table WD_TABLE_ALIGNMENT
()