python-docx
Programmatically read, modify, and create Word documents (.docx) with python-docx library
Skill by cxcscmu
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/cxcscmu-python-docx
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: documents
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/python-docx
What's inside
- Skill name
python-docx- Description
- Programmatically read, modify, and create Word documents (.docx) with python-docx library
- License
- MIT
- Instructions
- 137 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# Python-docx: Working with Word Documents
## Overview
The `python-docx` library allows you to create, read, and update Microsoft Word (.docx) files programmatically. It's essential for automating document generation, template filling, and Word document manipulation in Python.
## Installation
```bash
pip install python-docx
```
## Core Concepts
### Document Structure
- **Document**: Root object representing the entire .docx file
- **Paragraphs**: Text blocks in the document
- **Runs**: Individual text segments within a paragraph (can have different formatting)
- **Tables**: Structured data with rows/cells
- **Sections**: Document sections with different headers/footers
## Common Operations
### Loading and Saving Documents
```python
from docx import Document
# Open existing document
doc = Document('template.docx')
# Create new document
doc = Document()
# Save document
doc.save('output.docx')
```
### Working with Paragraphs and Text
```python
# Access all paragraphs
for para in doc.paragraphs:
print(para.text)
# Add new paragraph
new_para = doc.add_paragraph('Text here')
# Add text with formatting
run = new_para.add_run('Bold text')
run.bold = True
```
### Finding and Replacing Text
```python
# Search through all paragraphs and runs
for para in doc.paragraphs:
for run in para.runs:
if '{{PLACEHOLDER}}' in run.text:
run.text = run.text.replace('{{PLACEHOLDER}}', 'replacement')
# Note: Text can be split across multiple runs!
# A safer approach:
full_text = ''.join(run.text for run in para.runs)
if '{{PLACEHOLDER}}' in full_text:
# Clear all runs and recreate with replacement
for run in para.runs:
run.text = ''
para.text = full_text.replace('{{PLACEHOLDER}}', 'replacement')
```
### Working with Tables
```python
# Access table rows and cells
for table in doc.tables:
for row in table.rows:
for cell in row.cells:
print(cell.text)
# Replace text in cell
cell.text = cell.text.replace('{{PLACEHOLDER}}', 'value')
```
### Handling Multiple Runs
The trickiest part of python-docx is that text in a paragraph can be split across multiple "runs" (especially in templates). For placeholder replacement:
```python
def replace_text_in_paragraph(para, old_text, new_text):
"""Replace text handling split runs"""
if old_text in para.text:
# Clear existing runs
for run in para.runs:
run.text = ''
# Add new text as single run
para.text = new_text
```
## Important Considerations
1. **Text Fragmentation**: When you open a .docx file (especially templates), the same logical text might be split across multiple `run` objects due to formatting. Always check the full paragraph text before manipulating individual runs.
2. **Preserve Formatting**: When replacing text, consider whether you want to preserve the original formatting or apply new formatting.
3. **Iterating Safely**: If modifying document structure while iterating, make copies of lists first:
```python
paragraphs = list(doc.paragraphs) # Create copy
for para in paragraphs:
# Safe to modify now
```
4. **Headers/Footers**: Accessed via `doc.sections[0].header` and `doc.sections[0].footer`
## Example: Template Filling
```python
from docx import Document
def fill_template(template_path, replacements, output_path):
doc = Document(template_path)
# Replace in paragraphs
for para in doc.paragraphs:
for key, value in replacements.items():
if key in para.text:
para.text = para.text.replace(key, value)From cxcscmu/SkillLearnBench, MIT.
More from cxcscmu/SkillLearnBench
- 0.523score
skill-creator
cxcscmu
Create modular skill documents (SKILL.md files) for Claude Code.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
package-lock-parsing
cxcscmu
Parse and extract package information from npm package-lock.json files to identify dependencies and their installed versions.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
mandarin-rhyming-guide
cxcscmu
Master modern Mandarin pinyin finals and tone systems to create accurate rhymes for classical poetry following contemporary pronunciation standards.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
trivy-vulnerability-scanning
cxcscmu
Use Trivy vulnerability scanner in offline mode to detect CVEs in npm dependencies and generate structured JSON reports.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
cvss-score-extraction
cxcscmu
Extract and handle CVSS scores from multiple vulnerability data sources (NVD, GHSA, RedHat) with proper fallback priority.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
github-metrics-processing
cxcscmu
Process GitHub API data to calculate PR/issue metrics including merge time averages, author rankings, and bug categorization.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
security-audit-csv-reporting
cxcscmu
Generate structured CSV security audit reports from vulnerability data with proper filtering, formatting, and field mapping.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
classical-poetry-peace-theme
cxcscmu
Compose classical Chinese poetry on peace themes using authentic imagery, perspective shifts, and the voice of ordinary people experiencing war's aftermath.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
seven-char-regulated-verse
cxcscmu
Master the structure, tonal patterns, and rhyming requirements of classical seven-character regulated verse (七言律诗) in Chinese poetry.
SkillDFreshness: D★ 91Claude Code +9 - 0.512score
jackson-deserialization-validation
cxcscmu
Securing Jackson JSON deserialization by validating input before processing and preventing unknown properties.
SkillDFreshness: D★ 91Claude Code +9 - 0.512score
scala-option-either
cxcscmu
Translating Python's None/Optional to Scala's Option, Either, and Try types
SkillDFreshness: D★ 91Claude Code +9 - 0.512score
git-patch-workflow
cxcscmu
Creating, managing, and applying unified diff patches with Git for source code modifications.
SkillDFreshness: D★ 91Claude Code +9
Signals
- Stars
- 91
- Forks
- 7
- Open issues
- 6
- Last commit (this folder)
- Apr 24, 2026 (6 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/cxcscmu/SkillLearnBench
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from cxcscmu
- 0.523score
skill-creator
cxcscmu
Create modular skill documents (SKILL.md files) for Claude Code.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
seven-char-regulated-verse
cxcscmu
Master the structure, tonal patterns, and rhyming requirements of classical seven-character regulated verse (七言律诗) in Chinese poetry.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
security-audit-csv-reporting
cxcscmu
Generate structured CSV security audit reports from vulnerability data with proper filtering, formatting, and field mapping.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
classical-poetry-peace-theme
cxcscmu
Compose classical Chinese poetry on peace themes using authentic imagery, perspective shifts, and the voice of ordinary people experiencing war's aftermath.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
cvss-score-extraction
cxcscmu
Extract and handle CVSS scores from multiple vulnerability data sources (NVD, GHSA, RedHat) with proper fallback priority.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
mandarin-rhyming-guide
cxcscmu
Master modern Mandarin pinyin finals and tone systems to create accurate rhymes for classical poetry following contemporary pronunciation standards.
SkillDFreshness: D★ 91Claude Code +9
Cite this page
python-docx skill. Agent Mart. https://agentmart.dev/skills/cxcscmu-python-docx (last updated 2026-10-24)