pubmed-proto 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,5 @@
1
+ generated/
2
+ dist/
3
+ __pycache__/
4
+ *.pyc
5
+ .venv/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Centre for Population Genomics
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,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: pubmed-proto
3
+ Version: 0.1.0
4
+ Summary: Typed protobuf + pydantic models and converters for NLM PubMed XML.
5
+ Project-URL: Repository, https://github.com/populationgenomics/pubmed-proto
6
+ Project-URL: Issues, https://github.com/populationgenomics/pubmed-proto/issues
7
+ Author: Centre for Population Genomics
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: bioinformatics,ncbi,protobuf,pubmed,pydantic,xml
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.11
21
+ Requires-Dist: lxml
22
+ Requires-Dist: protobuf>=6.32.1
23
+ Requires-Dist: pydantic>=2
24
+ Description-Content-Type: text/markdown
25
+
26
+ # pubmed-proto
27
+
28
+ Generates **`pubmed_proto`** — a typed Python package for parsing NLM PubMed XML
29
+ into protobuf and pydantic models — from the PubMed DTD.
30
+
31
+ This repository is the **generator**, not the package. It holds the inputs
32
+ (`pubmed.dtd`, `pubmed_transforms.yaml`) and drives
33
+ [`xsd-former`](https://github.com/populationgenomics/xsd-former) (the
34
+ `xsdformer` CLI) to emit the `pubmed_proto` source tree, which is then built into
35
+ a wheel and published to PyPI. The generated tree (`generated/`) and build
36
+ outputs (`dist/`) are gitignored — only the inputs are version-controlled.
37
+
38
+ ## Consuming `pubmed_proto`
39
+
40
+ Depend on the published wheel, not this repo:
41
+
42
+ ```
43
+ pip install pubmed_proto # or: uv add pubmed_proto
44
+ ```
45
+
46
+ ```python
47
+ from lxml import etree
48
+ from pubmed_proto import xml_converter, pydantic_converter, models
49
+
50
+ tree = etree.parse("efetch_output.xml")
51
+ article_el = tree.getroot().find("PubmedArticle")
52
+
53
+ proto = xml_converter.PubmedArticle(article_el) # XML -> protobuf
54
+ model = pydantic_converter.PubmedArticle_from_proto(proto) # protobuf -> pydantic
55
+ json_str = model.model_dump_json() # pydantic -> JSON
56
+ ```
57
+
58
+ The package exposes four modules (all typed; ships `py.typed`):
59
+
60
+ | module | purpose |
61
+ | -------------------- | -------------------------------------------------- |
62
+ | `pubmed_pb2` | compiled protobuf messages (`Article`, `Author`, …) |
63
+ | `models` | pydantic models mirroring the protobuf schema |
64
+ | `xml_converter` | PubMed XML → protobuf (per-message factory funcs) |
65
+ | `pydantic_converter` | protobuf ↔ pydantic (`X_from_proto` / `X_to_proto`) |
66
+
67
+ ## Developing the generator
68
+
69
+ Requires [`uv`](https://docs.astral.sh/uv/).
70
+
71
+ ```
72
+ make generate # DTD + transforms -> generated/pubmed_proto/
73
+ make build # generate, then build the wheel into dist/
74
+ make clean # remove generated/ and dist/
75
+ uv run --group test pytest # round-trip gate over real PubMed records
76
+ ```
77
+
78
+ Shaping the output is done in **`pubmed_transforms.yaml`** — dropping
79
+ book/admin types, flattening list wrappers, coercing booleans/timestamps, and
80
+ serializing rich-text fields to markdown. See the
81
+ [`xsd-former`](https://github.com/populationgenomics/xsd-former) docs for the
82
+ transform reference.
83
+
84
+ ## Provenance & attribution
85
+
86
+ `pubmed.dtd` is derived from the **U.S. National Library of Medicine PubMed
87
+ DTD**, version `pubmed_250101` (dated 2024-08-28):
88
+
89
+ <https://dtd.nlm.nih.gov/ncbi/pubmed/out/pubmed_250101.dtd>
90
+
91
+ NLM DTDs are U.S. Government works and public domain in the United States; the
92
+ MIT `LICENSE` in this repo covers CPG's own files (transforms, generator wiring,
93
+ tests), not the NLM DTD.
94
+
95
+ **Local modification:** the external MathML module include
96
+ (`<!ENTITY % mathml-in-pubmed SYSTEM "mathml-in-pubmed.mod">` and its reference)
97
+ was removed so the DTD is self-contained for schema generation — MathML markup
98
+ in titles/abstracts is not modelled. With that one include removed, the file is
99
+ byte-identical to upstream `pubmed_250101`.
100
+
101
+ The DTD is **vendored deliberately, not fetched at build time**: it's a modified
102
+ derivative (so a fetch wouldn't reproduce it), and pinning the exact bytes keeps
103
+ the generated schema reproducible. The full provenance also lives in a comment
104
+ at the top of `pubmed.dtd`.
105
+
106
+ ## Releasing
107
+
108
+ The published version is **`build.version` in `pubmed_transforms.yaml`** (what
109
+ `xsdformer` stamps into the wheel). To release:
110
+
111
+ 1. Bump `build.version` in `pubmed_transforms.yaml`.
112
+ 2. Publish a GitHub Release tagged `vX.Y.Z` matching that version.
113
+
114
+ The `release` workflow generates, builds, and publishes to PyPI via Trusted
115
+ Publishing (OIDC). It fails if the tag and `build.version` disagree.
@@ -0,0 +1,90 @@
1
+ # pubmed-proto
2
+
3
+ Generates **`pubmed_proto`** — a typed Python package for parsing NLM PubMed XML
4
+ into protobuf and pydantic models — from the PubMed DTD.
5
+
6
+ This repository is the **generator**, not the package. It holds the inputs
7
+ (`pubmed.dtd`, `pubmed_transforms.yaml`) and drives
8
+ [`xsd-former`](https://github.com/populationgenomics/xsd-former) (the
9
+ `xsdformer` CLI) to emit the `pubmed_proto` source tree, which is then built into
10
+ a wheel and published to PyPI. The generated tree (`generated/`) and build
11
+ outputs (`dist/`) are gitignored — only the inputs are version-controlled.
12
+
13
+ ## Consuming `pubmed_proto`
14
+
15
+ Depend on the published wheel, not this repo:
16
+
17
+ ```
18
+ pip install pubmed_proto # or: uv add pubmed_proto
19
+ ```
20
+
21
+ ```python
22
+ from lxml import etree
23
+ from pubmed_proto import xml_converter, pydantic_converter, models
24
+
25
+ tree = etree.parse("efetch_output.xml")
26
+ article_el = tree.getroot().find("PubmedArticle")
27
+
28
+ proto = xml_converter.PubmedArticle(article_el) # XML -> protobuf
29
+ model = pydantic_converter.PubmedArticle_from_proto(proto) # protobuf -> pydantic
30
+ json_str = model.model_dump_json() # pydantic -> JSON
31
+ ```
32
+
33
+ The package exposes four modules (all typed; ships `py.typed`):
34
+
35
+ | module | purpose |
36
+ | -------------------- | -------------------------------------------------- |
37
+ | `pubmed_pb2` | compiled protobuf messages (`Article`, `Author`, …) |
38
+ | `models` | pydantic models mirroring the protobuf schema |
39
+ | `xml_converter` | PubMed XML → protobuf (per-message factory funcs) |
40
+ | `pydantic_converter` | protobuf ↔ pydantic (`X_from_proto` / `X_to_proto`) |
41
+
42
+ ## Developing the generator
43
+
44
+ Requires [`uv`](https://docs.astral.sh/uv/).
45
+
46
+ ```
47
+ make generate # DTD + transforms -> generated/pubmed_proto/
48
+ make build # generate, then build the wheel into dist/
49
+ make clean # remove generated/ and dist/
50
+ uv run --group test pytest # round-trip gate over real PubMed records
51
+ ```
52
+
53
+ Shaping the output is done in **`pubmed_transforms.yaml`** — dropping
54
+ book/admin types, flattening list wrappers, coercing booleans/timestamps, and
55
+ serializing rich-text fields to markdown. See the
56
+ [`xsd-former`](https://github.com/populationgenomics/xsd-former) docs for the
57
+ transform reference.
58
+
59
+ ## Provenance & attribution
60
+
61
+ `pubmed.dtd` is derived from the **U.S. National Library of Medicine PubMed
62
+ DTD**, version `pubmed_250101` (dated 2024-08-28):
63
+
64
+ <https://dtd.nlm.nih.gov/ncbi/pubmed/out/pubmed_250101.dtd>
65
+
66
+ NLM DTDs are U.S. Government works and public domain in the United States; the
67
+ MIT `LICENSE` in this repo covers CPG's own files (transforms, generator wiring,
68
+ tests), not the NLM DTD.
69
+
70
+ **Local modification:** the external MathML module include
71
+ (`<!ENTITY % mathml-in-pubmed SYSTEM "mathml-in-pubmed.mod">` and its reference)
72
+ was removed so the DTD is self-contained for schema generation — MathML markup
73
+ in titles/abstracts is not modelled. With that one include removed, the file is
74
+ byte-identical to upstream `pubmed_250101`.
75
+
76
+ The DTD is **vendored deliberately, not fetched at build time**: it's a modified
77
+ derivative (so a fetch wouldn't reproduce it), and pinning the exact bytes keeps
78
+ the generated schema reproducible. The full provenance also lives in a comment
79
+ at the top of `pubmed.dtd`.
80
+
81
+ ## Releasing
82
+
83
+ The published version is **`build.version` in `pubmed_transforms.yaml`** (what
84
+ `xsdformer` stamps into the wheel). To release:
85
+
86
+ 1. Bump `build.version` in `pubmed_transforms.yaml`.
87
+ 2. Publish a GitHub Release tagged `vX.Y.Z` matching that version.
88
+
89
+ The `release` workflow generates, builds, and publishes to PyPI via Trusted
90
+ Publishing (OIDC). It fails if the tag and `build.version` disagree.
@@ -0,0 +1,4 @@
1
+ from pubmed_proto import pubmed_pb2 as pubmed_pb2
2
+ from pubmed_proto import models as models
3
+ from pubmed_proto import pydantic_converter as pydantic_converter
4
+ from pubmed_proto import xml_converter as xml_converter