parse-docx 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 wispsy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,51 @@
1
+ Metadata-Version: 2.4
2
+ Name: parse-docx
3
+ Version: 0.1.0
4
+ Summary: Bounded, dependency-free DOCX parsing for Python
5
+ Author: wispsy
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Programming Language :: Python :: 3.14
10
+ Classifier: Typing :: Typed
11
+ Requires-Python: >=3.14
12
+ Project-URL: Repository, https://github.com/wispsy/parse-docx
13
+ Project-URL: Issues, https://github.com/wispsy/parse-docx/issues
14
+ Description-Content-Type: text/markdown
15
+
16
+ # parse-docx
17
+ `parse-docx` is a bounded, dependency-free DOCX parser for Python 3.14+.
18
+ It reads the Office Open XML package without executing or resolving document
19
+ content and returns an immutable, source-part-aware document model.
20
+
21
+ ```python
22
+ from parse_docx import load
23
+
24
+ document = load("report.docx")
25
+ print(document.text)
26
+
27
+ for block in document.blocks:
28
+ print(block.source_part, block)
29
+ ```
30
+
31
+ The model preserves paragraph and table order, run formatting, common heading
32
+ styles, basic list numbering, and inert hyperlink targets. Headers, footers,
33
+ footnotes, and endnotes are available separately. `Document.text` provides a
34
+ safe plain-text projection of the body.
35
+
36
+ See [supported features](docs/supported-features.md) and
37
+ [security boundaries](docs/security.md) for parsing details, limits, and
38
+ unsupported content.
39
+
40
+ ## Development
41
+
42
+ ```sh
43
+ uv sync --locked
44
+ uv run --frozen python -W error::ResourceWarning -m pytest -q
45
+ uv run --frozen python scripts/check_distribution.py --output-dir dist
46
+ ```
47
+
48
+ The distribution is named `parse-docx`; the Python import package is
49
+ `parse_docx`.
50
+
51
+ See [release instructions](docs/releasing.md) for Trusted Publishing setup.
@@ -0,0 +1,36 @@
1
+ # parse-docx
2
+ `parse-docx` is a bounded, dependency-free DOCX parser for Python 3.14+.
3
+ It reads the Office Open XML package without executing or resolving document
4
+ content and returns an immutable, source-part-aware document model.
5
+
6
+ ```python
7
+ from parse_docx import load
8
+
9
+ document = load("report.docx")
10
+ print(document.text)
11
+
12
+ for block in document.blocks:
13
+ print(block.source_part, block)
14
+ ```
15
+
16
+ The model preserves paragraph and table order, run formatting, common heading
17
+ styles, basic list numbering, and inert hyperlink targets. Headers, footers,
18
+ footnotes, and endnotes are available separately. `Document.text` provides a
19
+ safe plain-text projection of the body.
20
+
21
+ See [supported features](docs/supported-features.md) and
22
+ [security boundaries](docs/security.md) for parsing details, limits, and
23
+ unsupported content.
24
+
25
+ ## Development
26
+
27
+ ```sh
28
+ uv sync --locked
29
+ uv run --frozen python -W error::ResourceWarning -m pytest -q
30
+ uv run --frozen python scripts/check_distribution.py --output-dir dist
31
+ ```
32
+
33
+ The distribution is named `parse-docx`; the Python import package is
34
+ `parse_docx`.
35
+
36
+ See [release instructions](docs/releasing.md) for Trusted Publishing setup.
@@ -0,0 +1,38 @@
1
+ # Releasing
2
+
3
+ Releases are published to PyPI from tags matching the package version (for
4
+ example, `v0.1.0`). The release workflow checks that the tag matches
5
+ `pyproject.toml` and that its commit is already on `main`. It builds exactly one
6
+ source distribution and one wheel, verifies their metadata, and smoke-tests the
7
+ installed wheel before publishing the artifacts with PyPI Trusted Publishing.
8
+ No long-lived PyPI token is used.
9
+
10
+ ## Trusted Publisher setup
11
+
12
+ 1. In the GitHub repository settings, create an environment named `pypi`. No
13
+ environment secrets are required.
14
+ 2. In the PyPI project's publishing settings, configure the Trusted Publisher
15
+ with owner `wispsy`, repository `parse-docx`, workflow filename
16
+ `release.yaml`, and environment `pypi`. This project and publisher are
17
+ already set up. For a future project that does not yet exist on PyPI, add
18
+ the same values as a pending publisher at
19
+ <https://pypi.org/manage/account/publishing/> before its first release.
20
+
21
+ PyPI authorizes the release job through GitHub's OIDC token; no PyPI API token
22
+ or GitHub environment secret is needed.
23
+
24
+ ## Publishing
25
+
26
+ After the release commit is merged to `main`, create and push the matching
27
+ version tag:
28
+
29
+ ```sh
30
+ git tag v0.1.0
31
+ git push origin v0.1.0
32
+ ```
33
+
34
+ The tag-triggered workflow blocks publication unless the tag matches
35
+ `pyproject.toml`, its commit is on `main`, and the build contains exactly one
36
+ wheel and one source distribution with the expected package metadata and
37
+ working installed behavior. Twine also checks both artifacts before they are
38
+ passed to the publish job.
@@ -0,0 +1,18 @@
1
+ # Security boundaries
2
+
3
+ DOCX is a ZIP package and can contain active, externally referenced, or
4
+ resource-intensive content. `parse-docx` only reads selected package XML and
5
+ projects document structure and ordinary text. It never executes macros or
6
+ fields, fetches external relationships, opens embedded objects, renders
7
+ images, or edits a document. Hyperlink targets are retained as inert strings.
8
+
9
+ Package entry names are validated and no archive member is extracted to disk.
10
+ The parser rejects encrypted entries, duplicate names, excessive archive or
11
+ part sizes, suspicious compression ratios, DTDs, and entity declarations.
12
+ DTD and entity prohibitions are checked using the XML parser's encoding-aware
13
+ declaration events before ElementTree builds the document tree; UTF-8 and
14
+ UTF-16 declarations are both rejected.
15
+
16
+ The parser is not a malware scanner, sanitizer, or renderer. Treat returned
17
+ text and link targets as untrusted input; apply appropriate output escaping
18
+ and authorization in applications that display or use them.
@@ -0,0 +1,34 @@
1
+ # Supported features and API
2
+
3
+ `parse_docx.load(path, *, limits=None)` reads a filesystem path.
4
+ `parse_docx.loads(data, *, limits=None)` parses DOCX bytes already in memory;
5
+ `parse` is an alias for `loads`. They return an immutable `Document`.
6
+ Malformed packages, invalid XML, and limit breaches raise `ParseError`, whose
7
+ stable `code` identifies the failure.
8
+
9
+ `Document.blocks` contains body paragraphs and tables in source order.
10
+ Paragraphs contain ordered `Run` objects with text, bold, italic, underline,
11
+ and an optional inert hyperlink target. Paragraphs also expose the resolved
12
+ style name, heading level, list number/level/format, and source part. Tables
13
+ contain rows, cells, and recursively parsed cell blocks. `Document.text`
14
+ projects body paragraphs and tables into plain text; table cells are separated
15
+ by tabs and rows by newlines. List markers are included where numbering data is
16
+ available.
17
+
18
+ `Document.headers`, `Document.footers`, `Document.footnotes`, and
19
+ `Document.endnotes` expose referenced sections and notes separately; they are
20
+ not duplicated in `Document.text`. Runs in all parts identify their source
21
+ package part.
22
+
23
+ The initial release handles common WordprocessingML paragraphs, runs, tables,
24
+ heading styles, basic decimal and bullet numbering, hyperlinks, section
25
+ headers/footers, and footnotes/endnotes. It does not render page layout, resolve
26
+ fields, apply themes, or interpret embedded media. Revision-deleted text,
27
+ instructions, drawings, and unsupported markup are omitted from text output.
28
+ Unknown XML elements are ignored; strict OOXML namespaces are not supported;
29
+ the original DOCX bytes are not retained.
30
+
31
+ `Limits` defaults to 128 MiB compressed input, 256 MiB total declared
32
+ uncompressed package size, 16 MiB per package part, 4,096 package entries, and a
33
+ maximum compression ratio of 200:1. Customize these values to suit the
34
+ workload. Limits must be positive integers.
@@ -0,0 +1,46 @@
1
+ [project]
2
+ name = "parse-docx"
3
+ version = "0.1.0"
4
+ description = "Bounded, dependency-free DOCX parsing for Python"
5
+ readme = "README.md"
6
+ requires-python = ">=3.14"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ dependencies = []
10
+ classifiers = [
11
+ "Development Status :: 3 - Alpha",
12
+ "Programming Language :: Python :: 3.14",
13
+ "Typing :: Typed",
14
+ ]
15
+
16
+ [[project.authors]]
17
+ name = "wispsy"
18
+
19
+ [project.urls]
20
+ Repository = "https://github.com/wispsy/parse-docx"
21
+ Issues = "https://github.com/wispsy/parse-docx/issues"
22
+
23
+ [dependency-groups]
24
+ dev = ["pytest>=8"]
25
+
26
+ [build-system]
27
+ requires = ["uv_build>=0.13.6,<0.14.0"]
28
+ build-backend = "uv_build"
29
+
30
+ [tool.uv.build-backend]
31
+ source-include = [
32
+ "tests/**",
33
+ "docs/**",
34
+ "scripts/**",
35
+ "LICENSE",
36
+ "README.md",
37
+ ]
38
+
39
+ [tool.pytest.ini_options]
40
+ addopts = [
41
+ "-ra",
42
+ "--strict-config",
43
+ "--strict-markers",
44
+ ]
45
+ testpaths = ["tests"]
46
+ filterwarnings = ["error"]
@@ -0,0 +1,34 @@
1
+ [project]
2
+ name = "parse-docx"
3
+ version = "0.1.0"
4
+ description = "Bounded, dependency-free DOCX parsing for Python"
5
+ readme = "README.md"
6
+ requires-python = ">=3.14"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ authors = [{ name = "wispsy" }]
10
+ dependencies = []
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Programming Language :: Python :: 3.14",
14
+ "Typing :: Typed",
15
+ ]
16
+
17
+ [project.urls]
18
+ Repository = "https://github.com/wispsy/parse-docx"
19
+ Issues = "https://github.com/wispsy/parse-docx/issues"
20
+
21
+ [dependency-groups]
22
+ dev = ["pytest>=8"]
23
+
24
+ [build-system]
25
+ requires = ["uv_build>=0.13.6,<0.14.0"]
26
+ build-backend = "uv_build"
27
+
28
+ [tool.uv.build-backend]
29
+ source-include = ["tests/**", "docs/**", "scripts/**", "LICENSE", "README.md"]
30
+
31
+ [tool.pytest.ini_options]
32
+ addopts = ["-ra", "--strict-config", "--strict-markers"]
33
+ testpaths = ["tests"]
34
+ filterwarnings = ["error"]
@@ -0,0 +1,144 @@
1
+ """Build and smoke-test the source and wheel distributions."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import io
7
+ import os
8
+ import subprocess
9
+ import tarfile
10
+ import tempfile
11
+ import venv
12
+ import zipfile
13
+ from pathlib import Path
14
+
15
+ NAME = "parse-docx"
16
+ WHEEL_NAME = "parse_docx"
17
+ VERSION = "0.1.0"
18
+
19
+
20
+ def _metadata_fields(text: str) -> dict[str, str]:
21
+ fields: dict[str, str] = {}
22
+ for line in text.splitlines():
23
+ if line.startswith(("Name:", "Version:", "Requires-Dist:")):
24
+ key, value = line.split(":", 1)
25
+ fields[key] = value.strip()
26
+ return fields
27
+
28
+
29
+ def _verify_metadata(metadata: str, artifact: Path) -> None:
30
+ fields = _metadata_fields(metadata)
31
+ if fields.get("Name") != NAME or fields.get("Version") != VERSION:
32
+ raise SystemExit(f"{artifact.name} has unexpected package metadata: {fields}")
33
+ if "Requires-Dist" in fields:
34
+ raise SystemExit(f"{artifact.name} declares runtime dependencies")
35
+
36
+
37
+ def _minimal_docx() -> bytes:
38
+ parts = {
39
+ "[Content_Types].xml": (
40
+ b'<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">'
41
+ b'<Default Extension="xml" ContentType="application/xml"/></Types>'
42
+ ),
43
+ "_rels/.rels": (
44
+ b'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'
45
+ b'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/'
46
+ b'2006/relationships/officeDocument" Target="word/document.xml"/></Relationships>'
47
+ ),
48
+ "word/document.xml": (
49
+ b'<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/'
50
+ b'2006/main"><w:body><w:p><w:r><w:t>installed</w:t></w:r></w:p>'
51
+ b"</w:body></w:document>"
52
+ ),
53
+ }
54
+ output = io.BytesIO()
55
+ with zipfile.ZipFile(output, "w", compression=zipfile.ZIP_STORED) as archive:
56
+ for name, value in parts.items():
57
+ archive.writestr(name, value)
58
+ return output.getvalue()
59
+
60
+
61
+ def main() -> None:
62
+ argument_parser = argparse.ArgumentParser(description=__doc__)
63
+ argument_parser.add_argument("--tag", default="")
64
+ argument_parser.add_argument("--output-dir", required=True, type=Path)
65
+ args = argument_parser.parse_args()
66
+ if args.tag and args.tag != f"v{VERSION}":
67
+ raise SystemExit(
68
+ f"release tag {args.tag!r} does not match package version v{VERSION}"
69
+ )
70
+
71
+ output_dir = args.output_dir.resolve()
72
+ output_dir.mkdir(parents=True, exist_ok=True)
73
+ subprocess.run(["uv", "build", "--out-dir", str(output_dir)], check=True)
74
+ wheels = sorted(output_dir.glob(f"{WHEEL_NAME}-*.whl"))
75
+ sdists = sorted(output_dir.glob(f"{WHEEL_NAME}-*.tar.gz"))
76
+ if len(wheels) != 1 or len(sdists) != 1:
77
+ raise SystemExit(f"expected exactly one {NAME} wheel and source distribution")
78
+
79
+ wheel = wheels[0]
80
+ with zipfile.ZipFile(wheel) as archive:
81
+ members = archive.namelist()
82
+ package_metadata = next(
83
+ (member for member in members if member.endswith(".dist-info/METADATA")),
84
+ None,
85
+ )
86
+ if (
87
+ f"{WHEEL_NAME}/__init__.py" not in members
88
+ or f"{WHEEL_NAME}/py.typed" not in members
89
+ or package_metadata is None
90
+ ):
91
+ raise SystemExit(f"{wheel.name} is missing the package or wheel metadata")
92
+ _verify_metadata(archive.read(package_metadata).decode("utf-8"), wheel)
93
+
94
+ sdist = sdists[0]
95
+ with tarfile.open(sdist, "r:gz") as archive:
96
+ members = archive.getnames()
97
+ package_source = next(
98
+ (
99
+ member
100
+ for member in members
101
+ if member.endswith(f"/src/{WHEEL_NAME}/__init__.py")
102
+ ),
103
+ None,
104
+ )
105
+ package_metadata = next(
106
+ (member for member in members if member.endswith("/PKG-INFO")),
107
+ None,
108
+ )
109
+ if package_source is None or package_metadata is None:
110
+ raise SystemExit(f"{sdist.name} is missing the package or source metadata")
111
+ metadata_file = archive.extractfile(package_metadata)
112
+ if metadata_file is None:
113
+ raise SystemExit(f"{sdist.name} has unreadable source metadata")
114
+ _verify_metadata(metadata_file.read().decode("utf-8"), sdist)
115
+
116
+ with tempfile.TemporaryDirectory(prefix="parse-docx-install-") as directory:
117
+ environment = Path(directory) / "venv"
118
+ venv.EnvBuilder(with_pip=True).create(environment)
119
+ python = environment / (
120
+ "Scripts/python.exe" if os.name == "nt" else "bin/python"
121
+ )
122
+ subprocess.run(
123
+ [
124
+ str(python),
125
+ "-m",
126
+ "pip",
127
+ "install",
128
+ "--no-index",
129
+ "--no-deps",
130
+ str(wheel),
131
+ ],
132
+ check=True,
133
+ )
134
+ smoke = (
135
+ "from parse_docx import loads; "
136
+ f"assert loads({_minimal_docx()!r}).text == 'installed'"
137
+ )
138
+ subprocess.run([str(python), "-c", smoke], check=True)
139
+
140
+ print(f"Verified {sdist.name} and {wheel.name}")
141
+
142
+
143
+ if __name__ == "__main__":
144
+ main()
@@ -0,0 +1,27 @@
1
+ """Verify that a release tag matches the package version."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import tomllib
7
+ from pathlib import Path
8
+
9
+
10
+ def verify_release_tag(tag: str, version: str) -> None:
11
+ expected = f"v{version}"
12
+ if tag != expected:
13
+ raise SystemExit(f"release tag {tag!r} does not match package version {expected}")
14
+
15
+
16
+ def main() -> None:
17
+ parser = argparse.ArgumentParser(description=__doc__)
18
+ parser.add_argument("--tag", required=True)
19
+ args = parser.parse_args()
20
+
21
+ project = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8"))
22
+ version = project["project"]["version"]
23
+ verify_release_tag(args.tag, version)
24
+
25
+
26
+ if __name__ == "__main__":
27
+ main()
@@ -0,0 +1,33 @@
1
+ """A bounded, dependency-free DOCX parser."""
2
+
3
+ from .parser import (
4
+ Document,
5
+ HeaderFooter,
6
+ Limits,
7
+ Note,
8
+ Paragraph,
9
+ ParseError,
10
+ Run,
11
+ Table,
12
+ TableCell,
13
+ TableRow,
14
+ load,
15
+ loads,
16
+ parse,
17
+ )
18
+
19
+ __all__ = [
20
+ "Document",
21
+ "HeaderFooter",
22
+ "Limits",
23
+ "Note",
24
+ "Paragraph",
25
+ "ParseError",
26
+ "Run",
27
+ "Table",
28
+ "TableCell",
29
+ "TableRow",
30
+ "load",
31
+ "loads",
32
+ "parse",
33
+ ]