Extract Text From DOCX Resumes in Python with python-docx
Extract text from DOCX resumes in Python with python-docx. A short, clean way to turn Word CVs into AI-ready text — plus the one table caveat to know.
Drake Nguyen
Founder · System Architect
Why DOCX Is a Different Problem
In part 3 we pulled text out of PDFs. But plenty of candidates upload Word files instead, so to fill the same cv_text field we also need to extract text from a DOCX resume in Python. The good news: DOCX is far friendlier than PDF.
A DOCX file isn't a layout format like PDF — under the hood it's structured XML. That means the text is already stored as real, ordered content rather than glyphs scattered across a page, so we don't fight the spacing and column-order problems PDFs throw at us. A dedicated library gives us clean access to that structure directly.
Extracting Text With python-docx
The python-docx library reads Word documents natively. Install it first:
pip install python-docx
For a standard resume, extraction is just opening the document and joining its paragraphs:
from docx import Document
def extract_text_from_doc(file_path):
doc = Document(file_path)
return "\n".join(p.text for p in doc.paragraphs)
doc.paragraphs gives you every paragraph in the document in order, and p.text is its plain text. Joining them with newlines produces a clean, readable string — exactly the AI-ready CV text we're after. For the overwhelming majority of resumes, where the content flows as normal headings and paragraphs, this is all you need. No XML wrangling, no over-engineering — the direct solution to the actual problem.
One Caveat Worth Knowing
There's a single quirk of python-docx worth being aware of: doc.paragraphs returns paragraphs only — it does not include text that lives inside tables. Some resume templates lay out sections (skills, contact details, experience) inside table cells, and on those files the code above will silently skip that content.
For most resumes this never comes up, and the simple version is the right call to ship first. But it's a good challenge to take further yourself: python-docx also exposes doc.tables, so you can pull text out of table cells and append it. The trickier, more rewarding version is preserving true reading order — walking the document's underlying XML body so paragraphs and tables come out interleaved exactly as they appear, instead of all paragraphs followed by all tables. If you want to level up your parser, that's a worthwhile exercise to tackle on your own.
With both PDF and DOCX handled, the app can finally turn any uploaded CV into clean text. If you'd rather skip the full build and start from the finished, production-ready source, the complete code is available as a starter kit — otherwise, part 5 is next, where the AI enters the picture: using the OpenAI Agents SDK in a real Django app.