x-pug-utils 0.0.2__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
+ Metadata-Version: 2.4
2
+ Name: x-pug-utils
3
+ Version: 0.0.2
4
+ Summary: Parse PubChem PUG JSON into xsimple property and safety data.
5
+ License-Expression: MIT
6
+ Keywords: pubchem,pug,chemistry
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+
10
+ # x-pug-utils
11
+
12
+ Parse a PubChem PUG/PUG-View JSON document into the xsimple property and safety schema.
13
+
14
+ ```python
15
+ from x_pug_utils import parse_pug, parse_pug_file
16
+
17
+ result = parse_pug_file("COMPOUND_CID_2244.json")
18
+ # or: result = parse_pug(pug_json_dict)
19
+ ```
20
+
21
+ The package uses only the Python standard library and always returns the xsimple schema.
@@ -0,0 +1,12 @@
1
+ # x-pug-utils
2
+
3
+ Parse a PubChem PUG/PUG-View JSON document into the xsimple property and safety schema.
4
+
5
+ ```python
6
+ from x_pug_utils import parse_pug, parse_pug_file
7
+
8
+ result = parse_pug_file("COMPOUND_CID_2244.json")
9
+ # or: result = parse_pug(pug_json_dict)
10
+ ```
11
+
12
+ The package uses only the Python standard library and always returns the xsimple schema.
@@ -0,0 +1,18 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "x-pug-utils"
7
+ version = "0.0.2"
8
+ description = "Parse PubChem PUG JSON into xsimple property and safety data."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ keywords = ["pubchem", "pug", "chemistry"]
13
+
14
+ [tool.setuptools]
15
+ package-dir = {"" = "src"}
16
+
17
+ [tool.setuptools.packages.find]
18
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,33 @@
1
+ """Public API for parsing PubChem PUG data into the xsimple schema."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from collections.abc import Mapping
7
+ from pathlib import Path
8
+ from typing import Any
9
+
10
+ from ._parser import PubChemPugParser
11
+
12
+ __all__ = ["parse_pug", "parse_pug_file", "parse_pug_json"]
13
+
14
+
15
+ def parse_pug_json(pug_data: Mapping[str, Any]) -> dict[str, Any]:
16
+ """Parse a PUG JSON mapping and return only the xsimple schema."""
17
+ return PubChemPugParser(dict(pug_data)).parse(mode="xsimple")
18
+
19
+
20
+ def parse_pug_file(path: str | Path) -> dict[str, Any]:
21
+ """Read and parse a local PUG JSON file into the xsimple schema."""
22
+ with Path(path).open("r", encoding="utf-8") as handle:
23
+ data = json.load(handle)
24
+ if not isinstance(data, Mapping):
25
+ raise ValueError("PUG JSON root must be an object.")
26
+ return parse_pug_json(data)
27
+
28
+
29
+ def parse_pug(pug_data: Mapping[str, Any] | str | Path) -> dict[str, Any]:
30
+ """Parse a PUG JSON mapping or local JSON path into the xsimple schema."""
31
+ if isinstance(pug_data, Mapping):
32
+ return parse_pug_json(pug_data)
33
+ return parse_pug_file(pug_data)