netrias_client 0.0.1__py3-none-any.whl → 0.0.2__py3-none-any.whl
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.
Potentially problematic release.
This version of netrias_client might be problematic. Click here for more details.
- netrias_client/__init__.py +1 -1
- netrias_client/_client.py +29 -0
- netrias_client-0.0.2.dist-info/METADATA +153 -0
- {netrias_client-0.0.1.dist-info → netrias_client-0.0.2.dist-info}/RECORD +7 -7
- netrias_client-0.0.1.dist-info/METADATA +0 -222
- {netrias_client-0.0.1.dist-info → netrias_client-0.0.2.dist-info}/WHEEL +0 -0
- {netrias_client-0.0.1.dist-info → netrias_client-0.0.2.dist-info}/entry_points.txt +0 -0
- {netrias_client-0.0.1.dist-info → netrias_client-0.0.2.dist-info}/licenses/LICENSE +0 -0
netrias_client/__init__.py
CHANGED
netrias_client/_client.py
CHANGED
|
@@ -12,6 +12,8 @@ from dataclasses import replace
|
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
from uuid import uuid4
|
|
14
14
|
|
|
15
|
+
from importlib.metadata import PackageNotFoundError, version as package_version
|
|
16
|
+
|
|
15
17
|
from ._core import harmonize as _harmonize
|
|
16
18
|
from ._core import harmonize_async as _harmonize_async
|
|
17
19
|
from ._discovery import (
|
|
@@ -95,6 +97,7 @@ class NetriasClient:
|
|
|
95
97
|
with self._lock:
|
|
96
98
|
self._settings = settings
|
|
97
99
|
self._logger = logger
|
|
100
|
+
_emit_configuration_summary(settings=settings, logger=logger)
|
|
98
101
|
|
|
99
102
|
@property
|
|
100
103
|
def settings(self) -> Settings:
|
|
@@ -249,3 +252,29 @@ class NetriasClient:
|
|
|
249
252
|
"client not configured; call configure(api_key=...) before use"
|
|
250
253
|
)
|
|
251
254
|
return self._logger
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def _emit_configuration_summary(*, settings: Settings, logger: logging.Logger) -> None:
|
|
258
|
+
"""Log a sanitized summary of the active client configuration."""
|
|
259
|
+
|
|
260
|
+
summary = {
|
|
261
|
+
"package_version": _resolve_package_version(),
|
|
262
|
+
"discovery_url": settings.discovery_url,
|
|
263
|
+
"harmonization_url": settings.harmonization_url,
|
|
264
|
+
"timeout": settings.timeout,
|
|
265
|
+
"log_level": settings.log_level.value,
|
|
266
|
+
"confidence_threshold": settings.confidence_threshold,
|
|
267
|
+
"discovery_use_gateway_bypass": settings.discovery_use_gateway_bypass,
|
|
268
|
+
"log_directory": str(settings.log_directory) if settings.log_directory else None,
|
|
269
|
+
}
|
|
270
|
+
formatted = ", ".join(f"{key}={value}" for key, value in summary.items() if value is not None)
|
|
271
|
+
logger.info("client configured: %s", formatted)
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _resolve_package_version() -> str:
|
|
275
|
+
"""Return the installed package version or a fallback identifier."""
|
|
276
|
+
|
|
277
|
+
try:
|
|
278
|
+
return package_version("netrias_client")
|
|
279
|
+
except PackageNotFoundError:
|
|
280
|
+
return "0.0.0-dev"
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netrias_client
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Python client for the Netrias harmonization API
|
|
5
|
+
Project-URL: Homepage, https://github.com/netrias/netrias_client
|
|
6
|
+
Project-URL: Repository, https://github.com/netrias/netrias_client
|
|
7
|
+
Project-URL: Documentation, https://github.com/netrias/netrias_client#readme
|
|
8
|
+
Author-email: Chris Harman <charman@netrias.com>
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2025 Netrias
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: api,cde,client,harmonization,netrias
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Operating System :: OS Independent
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
+
Requires-Python: >=3.10
|
|
41
|
+
Requires-Dist: boto3
|
|
42
|
+
Requires-Dist: httpx
|
|
43
|
+
Provides-Extra: dev
|
|
44
|
+
Requires-Dist: basedpyright; extra == 'dev'
|
|
45
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
46
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
47
|
+
Requires-Dist: python-dotenv>=1.0; extra == 'dev'
|
|
48
|
+
Requires-Dist: ruff>=0.5.0; extra == 'dev'
|
|
49
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
50
|
+
Requires-Dist: ty; extra == 'dev'
|
|
51
|
+
Requires-Dist: typing-extensions; extra == 'dev'
|
|
52
|
+
Description-Content-Type: text/markdown
|
|
53
|
+
|
|
54
|
+
# Netrias Client
|
|
55
|
+
|
|
56
|
+
"""Explain how to install and exercise the Netrias harmonization client."""
|
|
57
|
+
|
|
58
|
+
## Install with `uv`
|
|
59
|
+
- Install `uv` once (or update): `curl -LsSf https://astral.sh/uv/install.sh | sh`
|
|
60
|
+
- Sync dependencies for a project that consumes the client:
|
|
61
|
+
```bash
|
|
62
|
+
uv add netrias_client
|
|
63
|
+
uv add python-dotenv # optional helper for loading .env files
|
|
64
|
+
```
|
|
65
|
+
- Prefer `uv run <command>` for executing scripts so the managed environment is reused automatically.
|
|
66
|
+
|
|
67
|
+
### Alternative: `pip`
|
|
68
|
+
```bash
|
|
69
|
+
python -m pip install netrias_client
|
|
70
|
+
python -m pip install python-dotenv # optional
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Quickstart Script
|
|
74
|
+
Reference script (save as `main.py`) showing a full harmonization round-trip:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
#!/usr/bin/env -S uv run python
|
|
78
|
+
# /// script
|
|
79
|
+
# requires-python = ">=3.13"
|
|
80
|
+
# dependencies = ["netrias_client", "python-dotenv"]
|
|
81
|
+
# ///
|
|
82
|
+
|
|
83
|
+
"""Exercise the packaged Netrias client against the live APIs."""
|
|
84
|
+
|
|
85
|
+
import asyncio
|
|
86
|
+
import os
|
|
87
|
+
from pathlib import Path
|
|
88
|
+
from typing import Final
|
|
89
|
+
|
|
90
|
+
from dotenv import load_dotenv
|
|
91
|
+
from netrias_client import NetriasClient
|
|
92
|
+
|
|
93
|
+
load_dotenv(override=True)
|
|
94
|
+
|
|
95
|
+
CSV_PATH: Final[Path] = Path("data/primary_diagnosis_1.csv")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
async def main() -> None:
|
|
99
|
+
client = NetriasClient()
|
|
100
|
+
client.configure(api_key=_resolve_api_key())
|
|
101
|
+
|
|
102
|
+
manifest = client.discover_cde_mapping(
|
|
103
|
+
source_csv=CSV_PATH,
|
|
104
|
+
target_schema="ccdi",
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
_ = await client.harmonize_async(
|
|
108
|
+
source_path=CSV_PATH,
|
|
109
|
+
manifest=manifest,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _resolve_api_key() -> str:
|
|
114
|
+
api_key = os.getenv("NETRIAS_API_KEY")
|
|
115
|
+
if api_key:
|
|
116
|
+
return api_key
|
|
117
|
+
msg = "Set NETRIAS_API_KEY in your environment or .env file"
|
|
118
|
+
raise RuntimeError(msg)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
if __name__ == "__main__":
|
|
122
|
+
asyncio.run(main())
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Steps
|
|
126
|
+
1. Install or update `uv` (see above).
|
|
127
|
+
2. Export `NETRIAS_API_KEY` (or add it to a local `.env`).
|
|
128
|
+
3. Adjust `CSV_PATH` to point at the source CSV you want to harmonize.
|
|
129
|
+
4. Run `uv run python main.py`.
|
|
130
|
+
|
|
131
|
+
The client logs its configuration (minus secrets) during `configure(...)` and
|
|
132
|
+
reports harmonization status plus output paths as the workflow progresses, so
|
|
133
|
+
no extra print statements are required.
|
|
134
|
+
|
|
135
|
+
## `configure()` Options
|
|
136
|
+
`NetriasClient.configure(...)` accepts additional tuning knobs. You can mix and match the ones you need:
|
|
137
|
+
|
|
138
|
+
| Parameter | Type | Purpose |
|
|
139
|
+
| --- | --- | --- |
|
|
140
|
+
| `api_key` | `str` | **Required.** Bearer token for authenticating with the Netrias services. |
|
|
141
|
+
| `timeout` | `float | None` | Override the default 6-hour timeout for long-running harmonization jobs. |
|
|
142
|
+
| `log_level` | `LogLevel | str | None` | Control verbosity (`INFO` by default). Accepts enum members or string names. |
|
|
143
|
+
| `confidence_threshold` | `float | None` | Minimum score (0–1) for keeping discovery recommendations; lower it to capture more tentative matches. |
|
|
144
|
+
| `discovery_use_gateway_bypass` | `bool | None` | Toggle the temporary AWS Lambda bypass path for discovery (defaults to `True`). Set to `False` once API Gateway limits are sufficient. |
|
|
145
|
+
| `log_directory` | `Path | str | None` | Directory for per-client log files. When omitted, logs stay on stdout. |
|
|
146
|
+
|
|
147
|
+
Configure only the options you need; unspecified values fall back to sensible defaults.
|
|
148
|
+
|
|
149
|
+
## Usage Notes
|
|
150
|
+
- `discover_cde_mapping(...)` samples CSV values and returns a manifest-ready payload; use the async variant if you’re already in an event loop.
|
|
151
|
+
- Call `harmonize(...)` (sync) or `harmonize_async(...)` (async) with the manifest to download a harmonized CSV. The result object reports status, description, and the output path.
|
|
152
|
+
- The package exposes `__version__` so callers can assert the installed release.
|
|
153
|
+
- Optional extras (`netrias_client[aws]`) add boto3 helpers for the temporary gateway bypass.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
netrias_client/__init__.py,sha256=
|
|
1
|
+
netrias_client/__init__.py,sha256=QpjkueW67jqpgsOf5ExSSdA7ylPWFvSCbuuoCg4wKXE,200
|
|
2
2
|
netrias_client/_adapter.py,sha256=dXJqrpkaAOiZI25gZm0RzFrSFaG4VefvLiM66oI4ziU,9241
|
|
3
|
-
netrias_client/_client.py,sha256=
|
|
3
|
+
netrias_client/_client.py,sha256=Si-XJZHQwFjC-PRTsL_e1Nh_U3tV5GyXlf1a95yjKNw,9703
|
|
4
4
|
netrias_client/_config.py,sha256=jY12kLOJ3OMn1YF7QeEq6nU2BaXCpPteoXDz7eprB8I,3098
|
|
5
5
|
netrias_client/_core.py,sha256=f77gwaHfu7lRK2eCSuwumfpU0UXQasZ9D2VVkbPQ68E,18741
|
|
6
6
|
netrias_client/_discovery.py,sha256=YVlA6dGBT4eSUBjyy82aM_Sm_4YK5ulZH_xqk5UJgZk,14380
|
|
@@ -12,8 +12,8 @@ netrias_client/_logging.py,sha256=5-lhBgp2hWp2K5ZTzz_ZwhJn_sxhSe_t__kdhuMTJnQ,13
|
|
|
12
12
|
netrias_client/_models.py,sha256=w_t-rpenLFZiBzLCdRlXaKPqgCrHCjAVoeXjPYF7wIY,1736
|
|
13
13
|
netrias_client/_validators.py,sha256=DvbaQ1Wkf4-W_H5A2PGiC-AxPN2tfpRFpH8vjETGIno,5894
|
|
14
14
|
netrias_client/scripts.py,sha256=jAdREIRbyuSvuvZt6tbRZ9ELfOzQyW9ZQcf2j2HIlsE,11113
|
|
15
|
-
netrias_client-0.0.
|
|
16
|
-
netrias_client-0.0.
|
|
17
|
-
netrias_client-0.0.
|
|
18
|
-
netrias_client-0.0.
|
|
19
|
-
netrias_client-0.0.
|
|
15
|
+
netrias_client-0.0.2.dist-info/METADATA,sha256=pJYfxKG5GYVmlSOfjCUCHB3jgvuuXuwpDCUQa2C9TFM,6254
|
|
16
|
+
netrias_client-0.0.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
17
|
+
netrias_client-0.0.2.dist-info/entry_points.txt,sha256=q7Uj2UATtRzlxefJNziCJQ9RXScH8MQzzWvA86Hfytc,162
|
|
18
|
+
netrias_client-0.0.2.dist-info/licenses/LICENSE,sha256=XzmWyunEynTK9hABeKX_9VEd1WcKSDQAM4IXIS-n8WU,1064
|
|
19
|
+
netrias_client-0.0.2.dist-info/RECORD,,
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: netrias_client
|
|
3
|
-
Version: 0.0.1
|
|
4
|
-
Summary: Python client for the Netrias harmonization API
|
|
5
|
-
Project-URL: Homepage, https://github.com/netrias/netrias_client
|
|
6
|
-
Project-URL: Repository, https://github.com/netrias/netrias_client
|
|
7
|
-
Project-URL: Documentation, https://github.com/netrias/netrias_client#readme
|
|
8
|
-
Author-email: Chris Harman <charman@netrias.com>
|
|
9
|
-
License: MIT License
|
|
10
|
-
|
|
11
|
-
Copyright (c) 2025 Netrias
|
|
12
|
-
|
|
13
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
in the Software without restriction, including without limitation the rights
|
|
16
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
-
furnished to do so, subject to the following conditions:
|
|
19
|
-
|
|
20
|
-
The above copyright notice and this permission notice shall be included in all
|
|
21
|
-
copies or substantial portions of the Software.
|
|
22
|
-
|
|
23
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
-
SOFTWARE.
|
|
30
|
-
License-File: LICENSE
|
|
31
|
-
Keywords: api,cde,client,harmonization,netrias
|
|
32
|
-
Classifier: Intended Audience :: Developers
|
|
33
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
-
Classifier: Operating System :: OS Independent
|
|
35
|
-
Classifier: Programming Language :: Python :: 3
|
|
36
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
37
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
38
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
-
Requires-Python: >=3.10
|
|
41
|
-
Requires-Dist: boto3
|
|
42
|
-
Requires-Dist: httpx
|
|
43
|
-
Provides-Extra: dev
|
|
44
|
-
Requires-Dist: basedpyright; extra == 'dev'
|
|
45
|
-
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
46
|
-
Requires-Dist: pytest>=7; extra == 'dev'
|
|
47
|
-
Requires-Dist: python-dotenv>=1.0; extra == 'dev'
|
|
48
|
-
Requires-Dist: ruff>=0.5.0; extra == 'dev'
|
|
49
|
-
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
50
|
-
Requires-Dist: ty; extra == 'dev'
|
|
51
|
-
Requires-Dist: typing-extensions; extra == 'dev'
|
|
52
|
-
Description-Content-Type: text/markdown
|
|
53
|
-
|
|
54
|
-
# Netrias Client
|
|
55
|
-
|
|
56
|
-
Python toolkit for working with the Netrias recommendation and harmonization services. The client wraps the HTTP APIs with strong typing, logging, and guard rails so analytics code can focus on describing data rather than orchestrating requests.
|
|
57
|
-
|
|
58
|
-
## Highlights
|
|
59
|
-
- **Stateful client facade** – instantiate `NetriasClient` and call `client.configure(...)` once.
|
|
60
|
-
- **Column discovery helpers** – derive column samples from CSV files, invoke the recommendation service, and normalize responses into `MappingDiscoveryResult` models.
|
|
61
|
-
- **Adapter utilities** – convert discovery output into harmonization-ready manifest payloads while applying confidence filters and CDE overrides.
|
|
62
|
-
- **Asynchronous harmonization loop** – submit jobs, poll for completion, download results, and version output files automatically to avoid accidental overwrites.
|
|
63
|
-
- **Extended timing logs** – discovery and harmonization emit duration metrics so you can spot slow calls quickly during live runs.
|
|
64
|
-
|
|
65
|
-
## Installation
|
|
66
|
-
|
|
67
|
-
The project targets Python 3.12+.
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
pip install netrias_client
|
|
71
|
-
|
|
72
|
-
# optional AWS helpers (gateway bypass)
|
|
73
|
-
pip install netrias_client[aws]
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
We recommend managing environments with [uv](https://github.com/astral-sh/uv):
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
# create or update a project that depends on netrias_client
|
|
80
|
-
uv add netrias_client
|
|
81
|
-
|
|
82
|
-
# install optional AWS helpers (gateway bypass)
|
|
83
|
-
uv add netrias_client[aws]
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
For local development within this repository:
|
|
87
|
-
|
|
88
|
-
```bash
|
|
89
|
-
uv sync --group dev # install development tooling
|
|
90
|
-
uv sync --group aws --group dev # include optional AWS dependencies
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
## Configuration
|
|
94
|
-
|
|
95
|
-
All client entry points require explicit configuration. Create a `NetriasClient`, then provide the API key; discovery and harmonization endpoints remain fixed by the library.
|
|
96
|
-
|
|
97
|
-
```python
|
|
98
|
-
from pathlib import Path
|
|
99
|
-
|
|
100
|
-
from netrias_client import NetriasClient
|
|
101
|
-
from netrias_client._models import LogLevel
|
|
102
|
-
|
|
103
|
-
client = NetriasClient()
|
|
104
|
-
client.configure(
|
|
105
|
-
api_key="<netrias api key>",
|
|
106
|
-
# Optional overrides:
|
|
107
|
-
timeout=21600.0, # seconds (default: 6 hours)
|
|
108
|
-
log_level=LogLevel.INFO,
|
|
109
|
-
confidence_threshold=0.80, # discovery adapter filter, 0.0–1.0
|
|
110
|
-
discovery_use_gateway_bypass=True, # toggle Lambda bypass (default: True)
|
|
111
|
-
log_directory=Path("logs/netrias"), # optional per-client log files
|
|
112
|
-
)
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
Configuration errors raise `ClientConfigurationError`. Calling `configure` again replaces the active settings snapshot and reinitializes the dedicated logger (refreshing file handlers when `log_directory` is supplied).
|
|
116
|
-
|
|
117
|
-
## End-to-End Workflow
|
|
118
|
-
|
|
119
|
-
The typical harmonization flow contains three steps:
|
|
120
|
-
|
|
121
|
-
```python
|
|
122
|
-
from pathlib import Path
|
|
123
|
-
|
|
124
|
-
from netrias_client import NetriasClient
|
|
125
|
-
|
|
126
|
-
client = NetriasClient()
|
|
127
|
-
client.configure(api_key="<netrias api key>")
|
|
128
|
-
|
|
129
|
-
csv_path = Path("/path/to/source.csv")
|
|
130
|
-
schema = "ccdi"
|
|
131
|
-
|
|
132
|
-
# 1. Ask the recommendation service for potential targets.
|
|
133
|
-
manifest_payload = client.discover_mapping_from_csv(
|
|
134
|
-
source_csv=csv_path,
|
|
135
|
-
target_schema=schema,
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
# 2. Kick off harmonization directly with the manifest payload.
|
|
139
|
-
result = client.harmonize(source_path=csv_path, manifest=manifest_payload)
|
|
140
|
-
print(result.status)
|
|
141
|
-
print(result.description)
|
|
142
|
-
print(result.file_path)
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
- `client.discover_mapping_from_csv(...)` samples up to 25 values per column (configurable), calls the API, and returns a manifest-ready payload (including static metadata such as CDE routes/IDs where configured).
|
|
146
|
-
- `client.harmonize(...)` submits a job and polls `GET /v1/jobs/{jobId}` until the backend returns success or failure. Downloaded CSVs are written next to the source file (versioned as `data.harmonized.v1.csv`, etc.). Pass `manifest_output_path=` if you also want to persist the manifest JSON for inspection.
|
|
147
|
-
|
|
148
|
-
### Timing Logs
|
|
149
|
-
|
|
150
|
-
Both discovery and harmonization log elapsed seconds for the full operation and for timeout/transport failures. Sample output:
|
|
151
|
-
|
|
152
|
-
```
|
|
153
|
-
INFO netrias_client: discover mapping start: schema=ccdi columns=12
|
|
154
|
-
INFO netrias_client: discover mapping complete: schema=ccdi suggestions=0 duration=47.12s
|
|
155
|
-
INFO netrias_client: harmonize start: file=data.csv
|
|
156
|
-
INFO netrias_client: harmonize finished: file=data.csv status=succeeded duration=182.45s
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
Use these metrics to separate slow API responses from downstream processing overhead.
|
|
160
|
-
|
|
161
|
-
## Adapter Notes
|
|
162
|
-
|
|
163
|
-
Discovery results are normalized to manifest payloads automatically; unmatched columns are logged so you can expand coverage. Confidence thresholds come from `configure(confidence_threshold=...)` and default to 0.8.
|
|
164
|
-
|
|
165
|
-
## Gateway Bypass (Temporary)
|
|
166
|
-
|
|
167
|
-
The module `netrias_client._gateway_bypass` exposes `invoke_cde_recommendation_alias(...)`, a stopgap helper that calls the `cde-recommendation` Lambda alias directly. This avoids API Gateway’s short timeout window but requires AWS credentials with `lambda:InvokeFunction` permission and the `boto3` dependency.
|
|
168
|
-
|
|
169
|
-
```python
|
|
170
|
-
from netrias_client._gateway_bypass import invoke_cde_recommendation_alias
|
|
171
|
-
|
|
172
|
-
result = invoke_cde_recommendation_alias(
|
|
173
|
-
target_schema="ccdi",
|
|
174
|
-
columns={"study_name": ["foo", "bar"]},
|
|
175
|
-
alias="prod",
|
|
176
|
-
region_name="us-east-2",
|
|
177
|
-
)
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
Install `boto3` (or `netrias-client[aws]` if provided) before importing the bypass module, and rotate IAM credentials frequently. Once API Gateway limits are raised, prefer the standard discovery flow again.
|
|
181
|
-
|
|
182
|
-
## Testing & Tooling
|
|
183
|
-
|
|
184
|
-
The repository ships with pytest-based integration tests plus lint/type tooling.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
```bash
|
|
188
|
-
uv run pytest
|
|
189
|
-
uv run ruff check
|
|
190
|
-
uv run basedpyright
|
|
191
|
-
uv build # produce wheel + sdist
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
Live verification scripts are located under `live_test/` and require a populated `.env` file containing `NETRIAS_API_KEY` (and optionally harmonization overrides while services converge).
|
|
195
|
-
|
|
196
|
-
## Project Layout
|
|
197
|
-
|
|
198
|
-
```
|
|
199
|
-
src/netrias_client/
|
|
200
|
-
__init__.py # re-exported public surface
|
|
201
|
-
_adapter.py # discovery → manifest conversion
|
|
202
|
-
_client.py # NetriasClient facade and state management
|
|
203
|
-
_config.py # settings validation helpers
|
|
204
|
-
_core.py # harmonization workflow
|
|
205
|
-
_discovery.py # discovery wrappers and CSV sampling
|
|
206
|
-
_errors.py # exception taxonomy
|
|
207
|
-
_http.py # HTTP primitives (submit/poll/download)
|
|
208
|
-
_io.py # streaming helpers
|
|
209
|
-
_logging.py # standardized logger setup
|
|
210
|
-
_models.py # dataclasses for structured responses
|
|
211
|
-
_validators.py # filesystem and payload validation
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
Tests reside under `src/netrias_client/tests/` and are excluded from the published wheel to keep installs slim; run them locally via `uv run pytest`.
|
|
215
|
-
|
|
216
|
-
## Contributing
|
|
217
|
-
|
|
218
|
-
1. `uv sync --group dev` (add `--group aws` if needed) to create the virtual environment.
|
|
219
|
-
2. `uv run pytest` to ensure the suite passes prior to committing.
|
|
220
|
-
3. Follow the repo conventions: keep functions focused, prefer typed interfaces, and favor logging key transitions over verbose chatter.
|
|
221
|
-
|
|
222
|
-
Pull requests should include updated documentation or fixtures when they alter API behavior or the manifest contract.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|