Metadata-Version: 2.5
Name: docx-fresh
Version: 0.1.0
Summary: Give python-docx documents fresh metadata instead of the default template's 2013 'python-docx / Macintosh Word' values.
Project-URL: Homepage, https://github.com/CokeRoach/docx-fresh
Project-URL: Issues, https://github.com/CokeRoach/docx-fresh/issues
Author: CokeRoach
License-Expression: MIT
License-File: LICENSE
Keywords: document properties,docx,metadata,python-docx,word
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Office/Business :: Office Suites
Classifier: Topic :: Text Processing
Requires-Python: >=3.10
Requires-Dist: lxml>=4.9
Requires-Dist: python-docx<2,>=1.0
Provides-Extra: test
Requires-Dist: pytest>=7; extra == 'test'
Description-Content-Type: text/markdown

# docx-fresh

Give [python-docx](https://github.com/python-openxml/python-docx) documents fresh metadata instead of the default template's.

`docx.Document()` without a template copies the document properties of python-docx's bundled `default.docx`. Every new file says it was written in 2013 by "python-docx" in Word for Mac, and Windows Explorer and Word's **File > Info** show it:

| Property | Without docx-fresh | With docx-fresh |
| --- | --- | --- |
| Author | `python-docx` | empty, or the name you pass |
| Last modified by | empty | same as author |
| Comments | `generated by python-docx` | empty |
| Created / Modified | 2013-12-23 23:15 UTC | now |
| Application (app.xml) | `Microsoft Macintosh Word` 14.0 | not set |
| Pages, words, lines (app.xml) | 1 page, 0 words | not set |
| Thumbnail | the template's | none |

## Install

```
pip install docx-fresh
```

## Use

```python
import docx
from docx_fresh import fresh

document = fresh(docx.Document(), author="Report bot")
document.add_heading("Weekly report", 1)
document.save("report.docx")
```

`fresh()` changes only values that still equal the default template's. A document made from your own template keeps its author, dates, app.xml and thumbnail, so it is safe to call on every document.

Options:

- `author`: written to Author and Last modified by. Default `""`.
- `now`: timezone-aware time for Created and Modified. Default: the current UTC time.

The page, word and line counts are removed rather than recomputed: only the application that lays the document out can count pages, and Word fills them in on its next save.

### Fix existing files

```
docx-fresh report.docx                  # in place
docx-fresh report.docx -o fixed.docx    # to a new file
docx-fresh report.docx --author "Report bot"
```

## Why not fixed in python-docx?

python-docx already sets Modified to now when a package has no document properties at all, but `default.docx` has them, so that code never runs. Until it is fixed upstream, `fresh()` is one line.

## Development

```
python -m venv .venv
.venv/Scripts/pip install -e ".[test]"     # or .venv/bin/pip on macOS and Linux
.venv/Scripts/python -m pytest
```

## License

MIT
