Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
629f942
rfctr: Blacken code base
scanny Sep 24, 2023
80740f2
build: move docx package under src/ directory
scanny Sep 25, 2023
6ac2c69
build: modernize packaging
scanny Sep 25, 2023
163cfc1
lint: add isort linting in ruff
scanny Sep 25, 2023
d509784
lint: fix C4xx comprehension errors
scanny Sep 26, 2023
878f758
lint: fix flake8-pytest-style diagnostics
scanny Sep 26, 2023
c8aad1c
lint: fix flake8-simplify diagnostics
scanny Sep 26, 2023
5cb952f
rfctr: remove Python 2 compatibility layer
scanny Sep 26, 2023
cbf940c
rfctr: bulk Python 2 formatting updates
scanny Sep 26, 2023
e88e1d5
rfctr: change param ref from asterisk to backticks
scanny Sep 28, 2023
1c5bb28
rfctr: bulk best-efforts PEP 257 docstrings
scanny Sep 28, 2023
5cd150e
rfctr: bulk test-layout updates
scanny Sep 27, 2023
ae6592b
rfctr: bulk remove __slots__
scanny Sep 30, 2023
99e9a0e
rfctr: modernize lazyproperty
scanny Sep 30, 2023
08ab7e6
rfctr: improve typing
scanny Sep 26, 2023
8280771
rfctr: add type-stubs for behave
scanny Sep 30, 2023
160e709
rfctr: rename private classes now used for typing
scanny Sep 30, 2023
5c1b2f0
rfctr: extract oxml.parser
scanny Sep 27, 2023
f07823c
spike: rejigger xmlchemy
scanny Sep 27, 2023
4935c30
docs: document hyperlink analysis
Mar 14, 2016
fd54be1
acpt: add Run inner-content scenarios
scanny Sep 30, 2023
45bf74b
rfctr: add types to Run and its tests
scanny Sep 30, 2023
ceb8cbe
rfctr: add types to Paragraph and its tests
scanny Oct 1, 2023
2e13d5c
run: Run.text includes no-break hyphen, etc.
scanny Sep 30, 2023
2364e90
run: add Run.contains_page_break
scanny Sep 30, 2023
08ee10a
run: add Run.iter_inner_content()
scanny Oct 1, 2023
1afedd0
acpt: add Paragraph inner-content scenarios
scanny Oct 1, 2023
b85b24f
para: add Paragraph.contains_page_break
scanny Oct 1, 2023
e654522
para: add Paragraph.hyperlinks
scanny Oct 1, 2023
57d93e1
para: add Paragraph.iter_inner_content()
scanny Oct 1, 2023
9dd2851
para: add Paragraph.rendered_page_breaks
scanny Oct 1, 2023
7868f3e
acpt: add Hyperlink properties scenarios
scanny Oct 1, 2023
16e3f10
hlink: add Hyperlink.address
scanny Oct 1, 2023
d0499b9
hlink: add Hyperlink.contains_page_break
scanny Oct 1, 2023
01061a8
hlink: add Hyperlink.runs
scanny Oct 1, 2023
a02c220
hlink: add Hyperlink.text
scanny Oct 1, 2023
9abd14a
para: Paragraph.text includes hyperlink text
scanny Oct 1, 2023
557fdee
acpt: add RenderedPageBreak split-para scenarios
scanny Oct 1, 2023
ac6c216
lrpb: add RenderedPageBreak.preceding_pa..fragment
scanny Oct 1, 2023
1e42c55
lrpb: add RenderedPageBreak.following_pa..fragment
scanny Oct 1, 2023
e47dfa2
docs: update docs with recent additions
scanny Oct 1, 2023
5b3ee80
release: prepare v1.0.0rc1 release
scanny Oct 2, 2023
8122909
rfctr: rework enums so they type-check
scanny Oct 7, 2023
58c2453
rfctr: Section type-checks clean
scanny Oct 8, 2023
b61b63b
rfctr: Paragraph type-checks clean
scanny Oct 8, 2023
ac26854
rfctr: Run type-checks clean
scanny Oct 9, 2023
44f9ede
rfctr: Font type-checks clean
scanny Oct 9, 2023
12a6bb8
rfctr: remove obsolete inherit-from-`object`
scanny Oct 9, 2023
9c9106f
section: Section.iter_inner_content()
scanny Oct 10, 2023
7ab9d31
docs: small docs fixes
scanny Oct 10, 2023
6df147e
release: prepare v1.0.0 release
scanny Oct 10, 2023
532ddd5
docs: add .readthedocs.yaml
scanny Oct 11, 2023
129dd83
fix: #1256 republish parse_xml() at docx.oxml
scanny Oct 11, 2023
96f80f7
hlink: add Hyperlink.fragment and .url
scanny Oct 12, 2023
b56f516
rfctr: improve typing
scanny Oct 12, 2023
8e05650
release: prepare v1.0.1 release
scanny Oct 12, 2023
e45fd78
fix: add build-backend in pyproject.toml
musicinmybrain Oct 13, 2023
8995a40
fix: include requirements files in PyPI sdist
musicinmybrain Oct 13, 2023
e441969
dev: set looponfailroots and filterwarnings
scanny Nov 3, 2023
a1c6b4f
xml: BaseOxmlElement subclasses etree.ElementBase
scanny Nov 2, 2023
523328c
rfctr: improve xmlchemy typing
scanny Nov 3, 2023
b7f5903
rfctr: resolve StoryChild conflation
scanny Nov 3, 2023
cf17811
rfctr: docx.shared type-checks strict
scanny Nov 3, 2023
e315139
rfctr: improve typing local to BlockItemContainer
scanny Nov 2, 2023
3c16691
xfail: for BlockItemContainer.iter_inner_content()
scanny Nov 3, 2023
f46751f
blk: add Document.iter_inner_content()
scanny Nov 3, 2023
24e4c1b
oxml: add .inner_content_elements props
scanny Nov 3, 2023
ee130dc
blk: add BlockItemContainer.iter_inner_content()
scanny Nov 3, 2023
16c7f34
docs: update docs for .iter_inner_content()
scanny Nov 3, 2023
57d3b9e
release: prepare v1.1.0 release
scanny Nov 4, 2023
630ecbf
rfctr(lint): tune in ruff settings
scanny Apr 29, 2024
5a22c52
rfctr: improve typing for tables
scanny Nov 6, 2023
cf5286c
rfctr: modernize table tests
scanny Apr 27, 2024
d8a3289
rfctr: improve expression
scanny Apr 27, 2024
6c34f12
rfctr: modernize opc.shared.lazyproperty
scanny Apr 29, 2024
4e5dd91
feat(table): add _Row.grid_cols_before
scanny Apr 27, 2024
1cfcee7
feat(table): add _Row.grid_cols_after
scanny Apr 27, 2024
5a1d614
docs: update Table docs
scanny Apr 28, 2024
6d49a69
rfctr(table): reimplement CT_Tc._tr_above
scanny Apr 29, 2024
382d43e
feat(table): add _Cell.grid_span
scanny Apr 28, 2024
7508051
feat(table): add CT_Tc.grid_offset
scanny Apr 28, 2024
512f269
rfctr(table): reimplement CT_Tc.tc_at_grid_offset
scanny Apr 28, 2024
f4a48b5
fix(table): fix _Row.cells can raise IndexError
scanny Apr 28, 2024
89b399b
feat(typing): add py.typed, improve public types
scanny Apr 29, 2024
94802e4
fix: fix some shortlist issues
scanny Apr 29, 2024
5a80006
fix(packaging): small packaging and doc tweaks
scanny Apr 30, 2024
0a09474
rfctr: resolve some import cycles
scanny Apr 30, 2024
e531576
release: prepare v1.1.1 release
scanny Apr 30, 2024
3f56b7d
rfctr(dev): use more performant `fd` for clean
scanny May 1, 2024
e493474
fix: XmlPart._rel_ref_count
scanny May 1, 2024
f246fde
rfctr: improve typing
scanny Apr 30, 2024
0ec5dcd
fix(pkg): pull lxml pin
scanny Apr 30, 2024
4cbbdab
fix: accommodate docxtpl use of Part._rels
scanny Apr 30, 2024
0a8e9c4
fix: Python 3.12 fixes
scanny May 1, 2024
0cf6d71
release: prepare v1.1.2 release
scanny May 1, 2024
3228bc5
proj: modernize project environment
scanny Jun 6, 2025
4262f4d
modn: improve type annotation
scanny Jun 6, 2025
afa670a
modn: modernize tests
scanny Jun 6, 2025
592fa8f
modn: improve ruff compliance
scanny Jun 6, 2025
d9da49b
fix: remove redundant w:pic "insertion"
scanny Jun 6, 2025
5cb32d7
xfail: acceptance test for Document.comments
scanny Jun 10, 2025
451747a
comments: add Document.comments
scanny Jun 10, 2025
8f184cc
comments: add DocumentPart.comments
scanny Jun 10, 2025
ae0e82d
comments: add DocumentPart._comments_part
scanny Jun 10, 2025
9c8a2e9
comments: add CommentsPart.comments
scanny Jun 10, 2025
595decc
comments: package-loader loads CommentsPart
scanny Jun 10, 2025
6c0024c
comments: add Comments.__len__()
scanny Jun 10, 2025
88ff3ca
comments: add Comments.__iter__()
scanny Jun 10, 2025
e2aec42
comments: add Comments.get()
scanny Jun 10, 2025
0eeaa2f
comments: add Comment.comment_id
scanny Jun 10, 2025
7cf36d6
xfail: acceptance test for Comment properties
scanny Jun 10, 2025
8af46fe
comments: add Comment.author
scanny Jun 10, 2025
cab50c5
comments: add Comment.initials
scanny Jun 10, 2025
cfb87e7
comments: add Comment.timestamp
scanny Jun 10, 2025
19175ad
comments: add Comment.paragraphs
scanny Jun 10, 2025
432dd15
drawing: add image extraction from Drawing
scanny Jun 10, 2025
d360409
xfail: acceptance test for Comment mutations
scanny Jun 10, 2025
8ac9fc4
comments: add Comments.add_comment()
scanny Jun 10, 2025
761f4cc
comments: add Comment.author, .initials setters
scanny Jun 10, 2025
66da522
xfail: acceptance test for Document.add_comment()
scanny Jun 10, 2025
af3b973
comments: add Document.add_comment()
scanny Jun 9, 2025
e3a321d
comments: add Run.mark_comment_range()
scanny Jun 10, 2025
a809d6c
comments: add Comment.text
scanny Jun 10, 2025
4fbe1f6
docs: add Comments docs
scanny Jun 12, 2025
1fe6601
build: small adjustments for tox
scanny Jun 13, 2025
e454546
release: prepare v1.2.0 release
scanny Jun 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .fdignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.tox
Session.vim
build/
docs/.build
features/_scratch
__pycache__/
src/*.egg-info
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/build/
.coverage
/dist/
/docs/.build/
/*.egg-info
/src/*.egg-info
*.pyc
.pytest_cache/
_scratch/
Expand Down
14 changes: 14 additions & 0 deletions .projections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"src/docx/*.py" : {
"alternate" : [
"tests/{dirname}/test_{basename}.py"
],
"type" : "source"
},
"tests/**/test_*.py" : {
"alternate" : [
"src/docx/{dirname}/{basename}.py"
],
"type" : "test"
}
}
19 changes: 19 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2

# -- set the OS, Python version and other tools you might need --
build:
os: ubuntu-22.04
tools:
python: "3.9"

# -- build documentation in the "docs/" directory with Sphinx --
sphinx:
configuration: docs/conf.py
# -- fail on all warnings to avoid broken references --
# fail_on_warning: true

# -- package versions required to build your documentation --
# -- see https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html --
python:
install:
- requirements: requirements-docs.txt
9 changes: 9 additions & 0 deletions .rgignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.tox
Session.vim
build/
docs/.build
features/_scratch
__pycache__/
ref/
src/*.egg-info
tests/test_files
56 changes: 56 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,62 @@
Release History
---------------

1.2.0 (2025-06-16)
++++++++++++++++++

- Add support for comments
- Drop support for Python 3.8, add testing for Python 3.13


1.1.2 (2024-05-01)
++++++++++++++++++

- Fix #1383 Revert lxml<=4.9.2 pin that breaks Python 3.12 install
- Fix #1385 Support use of Part._rels by python-docx-template
- Add support and testing for Python 3.12


1.1.1 (2024-04-29)
++++++++++++++++++

- Fix #531, #1146 Index error on table with misaligned borders
- Fix #1335 Tolerate invalid float value in bottom-margin
- Fix #1337 Do not require typing-extensions at runtime


1.1.0 (2023-11-03)
++++++++++++++++++

- Add BlockItemContainer.iter_inner_content()


1.0.1 (2023-10-12)
++++++++++++++++++

- Fix #1256: parse_xml() and OxmlElement moved.
- Add Hyperlink.fragment and .url


1.0.0 (2023-10-01)
+++++++++++++++++++

- Remove Python 2 support. Supported versions are 3.7+
- Fix #85: Paragraph.text includes hyperlink text
- Add #1113: Hyperlink.address
- Add Hyperlink.contains_page_break
- Add Hyperlink.runs
- Add Hyperlink.text
- Add Paragraph.contains_page_break
- Add Paragraph.hyperlinks
- Add Paragraph.iter_inner_content()
- Add Paragraph.rendered_page_breaks
- Add RenderedPageBreak.following_paragraph_fragment
- Add RenderedPageBreak.preceding_paragraph_fragment
- Add Run.contains_page_break
- Add Run.iter_inner_content()
- Add Section.iter_inner_content()


0.8.11 (2021-05-15)
+++++++++++++++++++

Expand Down
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include HISTORY.rst LICENSE README.rst tox.ini
graft docx/templates
include requirements*.txt
graft src/docx/templates
graft features
graft tests
graft docs
Expand Down
58 changes: 38 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,64 @@
BEHAVE = behave
MAKE = make
PYTHON = python
SETUP = $(PYTHON) ./setup.py
TWINE = $(PYTHON) -m twine

.PHONY: accept clean coverage docs readme register sdist test upload
.PHONY: accept build clean cleandocs coverage docs install opendocs sdist test
.PHONY: test-upload wheel

help:
@echo "Please use \`make <target>' where <target> is one or more of"
@echo " accept run acceptance tests using behave"
@echo " clean delete intermediate work product and start fresh"
@echo " cleandocs delete intermediate documentation files"
@echo " coverage run nosetests with coverage"
@echo " docs generate documentation"
@echo " opendocs open browser to local version of documentation"
@echo " register update metadata (README.rst) on PyPI"
@echo " sdist generate a source distribution into dist/"
@echo " upload upload distribution tarball to PyPI"
@echo " accept run acceptance tests using behave"
@echo " build generate both sdist and wheel suitable for upload to PyPI"
@echo " clean delete intermediate work product and start fresh"
@echo " cleandocs delete intermediate documentation files"
@echo " coverage run pytest with coverage"
@echo " docs generate documentation"
@echo " opendocs open browser to local version of documentation"
@echo " register update metadata (README.rst) on PyPI"
@echo " sdist generate a source distribution into dist/"
@echo " test run unit tests using pytest"
@echo " test-upload upload distribution to TestPyPI"
@echo " upload upload distribution tarball to PyPI"
@echo " wheel generate a binary distribution into dist/"

accept:
$(BEHAVE) --stop
uv run $(BEHAVE) --stop

build:
uv build

clean:
find . -type f -name \*.pyc -exec rm {} \;
# find . -type f -name \*.pyc -exec rm {} \;
fd -e pyc -I -x rm
rm -rf dist *.egg-info .coverage .DS_Store

cleandocs:
$(MAKE) -C docs clean

coverage:
py.test --cov-report term-missing --cov=docx tests/
uv run pytest --cov-report term-missing --cov=docx tests/

docs:
$(MAKE) -C docs html

install:
pip install -Ue .

opendocs:
open docs/.build/html/index.html

register:
$(SETUP) register

sdist:
$(SETUP) sdist
uv build --sdist

test:
uv run pytest -x

test-upload: sdist wheel
uv run $(TWINE) upload --repository testpypi dist/*

upload: clean sdist wheel
uv run $(TWINE) upload dist/*

upload:
$(SETUP) sdist upload
wheel:
uv build --wheel
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# python-docx

*python-docx* is a Python library for reading, creating, and updating Microsoft Word 2007+ (.docx) files.

## Installation

```
pip install python-docx
```

## Example

```python
>>> from docx import Document

>>> document = Document()
>>> document.add_paragraph("It was a dark and stormy night.")
<docx.text.paragraph.Paragraph object at 0x10f19e760>
>>> document.save("dark-and-stormy.docx")

>>> document = Document("dark-and-stormy.docx")
>>> document.paragraphs[0].text
'It was a dark and stormy night.'
```

More information is available in the [python-docx documentation](https://python-docx.readthedocs.org/en/latest/)
10 changes: 0 additions & 10 deletions README.rst

This file was deleted.

Binary file added docs/_static/img/comment-parts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions docs/api/comments.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

.. _comments_api:

Comment-related objects
=======================

.. currentmodule:: docx.comments


|Comments| objects
------------------

.. autoclass:: Comments()
:members:
:inherited-members:
:exclude-members:
part


|Comment| objects
------------------

.. autoclass:: Comment()
:members:
:inherited-members:
:exclude-members:
part
30 changes: 15 additions & 15 deletions docs/api/document.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,68 +50,68 @@ if that behavior is desired.

.. attribute:: author

*string* -- An entity primarily responsible for making the content of the
`string` -- An entity primarily responsible for making the content of the
resource.

.. attribute:: category

*string* -- A categorization of the content of this package. Example
`string` -- A categorization of the content of this package. Example
values might include: Resume, Letter, Financial Forecast, Proposal,
or Technical Presentation.

.. attribute:: comments

*string* -- An account of the content of the resource.
`string` -- An account of the content of the resource.

.. attribute:: content_status

*string* -- completion status of the document, e.g. 'draft'
`string` -- completion status of the document, e.g. 'draft'

.. attribute:: created

*datetime* -- time of intial creation of the document
`datetime` -- time of intial creation of the document

.. attribute:: identifier

*string* -- An unambiguous reference to the resource within a given
`string` -- An unambiguous reference to the resource within a given
context, e.g. ISBN.

.. attribute:: keywords

*string* -- descriptive words or short phrases likely to be used as
`string` -- descriptive words or short phrases likely to be used as
search terms for this document

.. attribute:: language

*string* -- language the document is written in
`string` -- language the document is written in

.. attribute:: last_modified_by

*string* -- name or other identifier (such as email address) of person
`string` -- name or other identifier (such as email address) of person
who last modified the document

.. attribute:: last_printed

*datetime* -- time the document was last printed
`datetime` -- time the document was last printed

.. attribute:: modified

*datetime* -- time the document was last modified
`datetime` -- time the document was last modified

.. attribute:: revision

*int* -- number of this revision, incremented by Word each time the
`int` -- number of this revision, incremented by Word each time the
document is saved. Note however |docx| does not automatically increment
the revision number when it saves a document.

.. attribute:: subject

*string* -- The topic of the content of the resource.
`string` -- The topic of the content of the resource.

.. attribute:: title

*string* -- The name given to the resource.
`string` -- The name given to the resource.

.. attribute:: version

*string* -- free-form version string
`string` -- free-form version string
2 changes: 1 addition & 1 deletion docs/api/shared.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ allowing values to be expressed in the units most appropriate to the context.
:members:
:undoc-members:

*r*, *g*, and *b* are each an integer in the range 0-255 inclusive. Using
`r`, `g`, and `b` are each an integer in the range 0-255 inclusive. Using
the hexidecimal integer notation, e.g. `0x42` may enhance readability
where hex RGB values are in use::

Expand Down
Loading