{"id":7626,"library":"python-docx-ml6","title":"python-docx-ml6: Microsoft Word .docx File Manipulation","description":"python-docx-ml6 is a Python library for creating, reading, and updating Microsoft Word 2007+ (.docx) files. It is a fork from the original `python-docx` library, specifically including feature requests provided by the open-source community that have not yet been merged into the upstream project. The current version is 1.0.2, released in November 2023, indicating an active development and maintenance cadence.","status":"active","version":"1.0.2","language":"en","source_language":"en","source_url":"https://github.com/ml6team/python-docx","tags":["word","docx","document automation","office","microsoft word","document generation"],"install":[{"cmd":"pip install python-docx-ml6","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Required for parsing and generating Office Open XML (OOXML) files.","package":"lxml","optional":false},{"reason":"Provides backported and experimental type hints for Python.","package":"typing-extensions","optional":true}],"imports":[{"note":"The primary class `Document` is imported from the `docx` module, not the top-level package name `python-docx-ml6`. Attempting to `import docx` directly will not provide access to the `Document` class without further qualification.","wrong":"import docx","symbol":"Document","correct":"from docx import Document"}],"quickstart":{"code":"from docx import Document\nfrom docx.shared import Inches\n\n# Create a new document\ndocument = Document()\n\n# Add a heading\ndocument.add_heading('Document Title', level=0)\n\n# Add a paragraph\np = document.add_paragraph('A plain paragraph having some ')\np.add_run('bold').bold = True\np.add_run(' and some ')\np.add_run('italic.').italic = True\n\n# Add a heading with level 1\ndocument.add_heading('Heading, level 1', level=1)\n\n# Add a picture\ndocument.add_picture('path/to/image.png', width=Inches(1.25))\n\n# Add a table\nrecords = (\n    (3, '101', 'Spam'),\n    (7, '422', 'Eggs'),\n    (4, '631', 'Spam, eggs, and bacon'),\n)\n\ntable = document.add_table(rows=1, cols=3)\nhdr_cells = table.rows[0].cells\nhdr_cells[0].text = 'Qty'\nhdr_cells[1].text = 'Id'\nhdr_cells[2].text = 'Desc'\nfor qty, id, desc in records:\n    row_cells = table.add_row().cells\n    row_cells[0].text = str(qty)\n    row_cells[1].text = id\n    row_cells[2].text = desc\n\ndocument.add_page_break()\n\n# Save the document\ndocument.save('demo.docx')\nprint(\"Document 'demo.docx' created successfully.\")","lang":"python","description":"This quickstart demonstrates how to create a new Word document, add headings, paragraphs with formatted text (bold/italic), insert an image, and create a simple table. It then saves the document to a .docx file."},"warnings":[{"fix":"Consult the `python-docx-ml6` GitHub repository's README or issue tracker for specific features and differences. Explicitly install `python-docx-ml6` if its features are desired, rather than the original `python-docx`.","message":"This library is a fork (`python-docx-ml6`) of the original `python-docx`. While it includes additional community-requested features, users migrating from the original `python-docx` or expecting identical behavior should verify specific functionalities, as there might be subtle differences or a divergent maintenance path.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement explicit checks in your code (e.g., `os.path.exists`) or save to unique filenames to prevent accidental data loss.","message":"Saving a document to an existing filename will silently overwrite the original file without any warning or prompt.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For comprehensive text replacement, iterate through `document.paragraphs`, `paragraph.runs`, or other document elements, checking and replacing text as needed, rather than relying on high-level single-call replacement functions if they exist.","message":"When replacing text or placeholders in a document, simple methods might only affect the first occurrence within a paragraph or run. Achieving global or multiple replacements often requires iterating through paragraphs and runs.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the `python-docx` changelog for migration guides if coming from ancient versions. Expect a rewrite of document manipulation logic if transitioning from pre-0.3.0 code.","message":"If migrating from very old versions of `python-docx` (0.2.x or earlier), be aware that versions 0.3.0 and later introduced significant API incompatibilities. While `python-docx-ml6` is a fork of a modern `python-docx`, this historical context is relevant for deep migrations.","severity":"breaking","affected_versions":"< 0.3.0 (original python-docx)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"First, ensure `python-docx-ml6` is installed in your active Python environment (`pip install python-docx-ml6`). Then, verify its presence (`pip show python-docx-ml6`). If you previously installed a package called `docx` (which is deprecated), uninstall it (`pip uninstall docx`) and reinstall `python-docx-ml6`.","cause":"The package `python-docx-ml6` was installed, but the Python interpreter cannot find the `docx` module. This often happens if the package wasn't installed in the active environment, or if an older, unmaintained package named `docx` was accidentally installed instead of `python-docx-ml6`.","error":"ModuleNotFoundError: No module named 'docx'"},{"fix":"Upgrade `python-docx-ml6` and its core dependencies to their latest stable versions: `pip install --upgrade python-docx-ml6 lxml`. Review the library's GitHub issues for any specific known deprecations in the current version.","cause":"This warning typically originates from an underlying dependency like `lxml`, or from using an older version of `python-docx` (or its fork `python-docx-ml6`) that had known deprecation issues. For instance, specific `python-docx` versions before 0.8.11 had a known deprecation warning.","error":"Deprecation Warning: This code will cease to work in future versions."},{"fix":"Confirm the installed version of `python-docx-ml6` (`pip show python-docx-ml6`). Consult the `ml6team/python-docx` GitHub repository for the specific API and features supported by this fork. If the feature is expected from the original `python-docx`, consider if `python-docx-ml6` has a different implementation or if the feature is simply not included in the fork.","cause":"The user might be expecting a feature that exists in the original `python-docx` or a different fork, or conversely, a feature that only exists in `python-docx-ml6` but is not present in the user's installed version or is called differently. This highlights the fork's specific feature set.","error":"AttributeError: 'Document' object has no attribute 'some_feature'"}]}