netrias_client 0.0.1__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 +9 -0
- netrias_client/_adapter.py +288 -0
- netrias_client/_client.py +251 -0
- netrias_client/_config.py +95 -0
- netrias_client/_core.py +560 -0
- netrias_client/_discovery.py +437 -0
- netrias_client/_errors.py +33 -0
- netrias_client/_gateway_bypass.py +208 -0
- netrias_client/_http.py +126 -0
- netrias_client/_io.py +28 -0
- netrias_client/_logging.py +46 -0
- netrias_client/_models.py +72 -0
- netrias_client/_validators.py +173 -0
- netrias_client/scripts.py +313 -0
- netrias_client-0.0.1.dist-info/METADATA +222 -0
- netrias_client-0.0.1.dist-info/RECORD +19 -0
- netrias_client-0.0.1.dist-info/WHEEL +4 -0
- netrias_client-0.0.1.dist-info/entry_points.txt +5 -0
- netrias_client-0.0.1.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"""Coordinate project command entry points.
|
|
2
|
+
|
|
3
|
+
'why': centralize developer workflows for `uv run` execution
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import logging
|
|
9
|
+
import os
|
|
10
|
+
import re
|
|
11
|
+
import shutil
|
|
12
|
+
import subprocess
|
|
13
|
+
import sys
|
|
14
|
+
import tempfile
|
|
15
|
+
from collections.abc import Mapping, Sequence
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Final, cast
|
|
19
|
+
|
|
20
|
+
_LOGGER = logging.getLogger("netrias_client.scripts")
|
|
21
|
+
_COMMANDS: Final[tuple[tuple[str, ...], ...]] = (
|
|
22
|
+
("pytest",),
|
|
23
|
+
("ruff", "check", "."),
|
|
24
|
+
("basedpyright", "."),
|
|
25
|
+
)
|
|
26
|
+
_REPO_ROOT: Final[Path] = Path(__file__).resolve().parents[2]
|
|
27
|
+
_PYPROJECT_PATH: Final[Path] = _REPO_ROOT / "pyproject.toml"
|
|
28
|
+
_PACKAGE_INIT_PATH: Final[Path] = Path(__file__).resolve().parent / "__init__.py"
|
|
29
|
+
_DIST_PATH: Final[Path] = _REPO_ROOT / "dist"
|
|
30
|
+
_VERSION_PATTERN: Final[re.Pattern[str]] = re.compile(r'^version\s*=\s*"(?P<value>[^"]+)"$', re.MULTILINE)
|
|
31
|
+
_INIT_VERSION_PATTERN: Final[re.Pattern[str]] = re.compile(r'^__version__\s*=\s*"(?P<value>[^"]+)"$', re.MULTILINE)
|
|
32
|
+
_REPOSITORY_CONFIG: Final[dict[str, tuple[str, str | None]]] = {
|
|
33
|
+
"testpypi": ("TEST_PYPI_TOKEN", "https://test.pypi.org/legacy/"),
|
|
34
|
+
"pypi": ("PYPI_TOKEN", None),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True)
|
|
39
|
+
class ReleaseOptions:
|
|
40
|
+
"""Capture release CLI arguments as structured options.
|
|
41
|
+
|
|
42
|
+
'why': keep parsing separate from orchestration logic
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
version: str | None
|
|
46
|
+
bump: str
|
|
47
|
+
repository: str | None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def check() -> None:
|
|
51
|
+
"""Run the combined test and lint pipeline invoked by `uv run check`.
|
|
52
|
+
|
|
53
|
+
'why': provide a single entry point that exits early on the first failure
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
_ensure_logging()
|
|
57
|
+
for command in _COMMANDS:
|
|
58
|
+
_run_command_or_raise(command)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def live_check() -> None:
|
|
62
|
+
"""Execute the live service smoke test harness.
|
|
63
|
+
|
|
64
|
+
'why': exercise production endpoints without duplicating CLI plumbing
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
_run_command_or_raise(("python", "-m", "netrias_client.live_test.test"))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def release(argv: Sequence[str] | None = None) -> None:
|
|
71
|
+
"""Run the release pipeline: bump version, validate, build, publish.
|
|
72
|
+
|
|
73
|
+
'why': streamline TestPyPI/PyPI releases from a single script
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
options = _parse_release_args(argv)
|
|
77
|
+
_ensure_logging()
|
|
78
|
+
target_version = _determine_target_version(options)
|
|
79
|
+
_update_versions(target_version)
|
|
80
|
+
_LOGGER.info("version synchronized → %s", target_version)
|
|
81
|
+
check()
|
|
82
|
+
artifacts = _build_distributions()
|
|
83
|
+
_verify_artifacts(artifacts)
|
|
84
|
+
if options.repository:
|
|
85
|
+
_publish_artifacts(options.repository)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _ensure_logging() -> None:
|
|
89
|
+
"""Provision a minimalist logging configuration for script execution."""
|
|
90
|
+
|
|
91
|
+
if not _LOGGER.handlers:
|
|
92
|
+
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _run_command(command: Sequence[str], *, env: Mapping[str, str] | None = None, display_command: Sequence[str] | None = None) -> int:
|
|
96
|
+
"""Run `command` and return its exit status without raising on failure.
|
|
97
|
+
|
|
98
|
+
'why': centralize subprocess logging and leave error handling to callers
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
shown = display_command or command
|
|
102
|
+
_LOGGER.info("→ %s", " ".join(shown))
|
|
103
|
+
completed = subprocess.run(command, check=False, env=dict(env) if env else None)
|
|
104
|
+
return completed.returncode
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _run_command_or_raise(
|
|
108
|
+
command: Sequence[str],
|
|
109
|
+
*,
|
|
110
|
+
env: Mapping[str, str] | None = None,
|
|
111
|
+
display_command: Sequence[str] | None = None,
|
|
112
|
+
) -> None:
|
|
113
|
+
"""Execute `command` and abort immediately on failure.
|
|
114
|
+
|
|
115
|
+
'why': surface the first failing command to halt composite workflows
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
exit_code = _run_command(command, env=env, display_command=display_command)
|
|
119
|
+
if exit_code != 0:
|
|
120
|
+
raise SystemExit(exit_code)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _parse_release_args(argv: Sequence[str] | None) -> ReleaseOptions:
|
|
124
|
+
"""Parse CLI arguments into a `ReleaseOptions` instance.
|
|
125
|
+
|
|
126
|
+
'why': isolate argparse wiring for straightforward testing
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
parser = argparse.ArgumentParser(prog="uv run release")
|
|
130
|
+
group = parser.add_mutually_exclusive_group()
|
|
131
|
+
_ = group.add_argument("--version", help="Explicit semantic version to publish")
|
|
132
|
+
_ = group.add_argument("--bump", choices=("patch", "minor", "major"), default="patch", help="Increment the current version")
|
|
133
|
+
_ = parser.add_argument("--publish", choices=("testpypi", "pypi"), dest="repository", help="Publish artifacts after verification")
|
|
134
|
+
namespace = parser.parse_args(list(argv) if argv is not None else sys.argv[1:])
|
|
135
|
+
version_arg = cast(str | None, getattr(namespace, "version", None))
|
|
136
|
+
bump_arg = cast(str | None, getattr(namespace, "bump", None))
|
|
137
|
+
repository_arg = cast(str | None, getattr(namespace, "repository", None))
|
|
138
|
+
bump = bump_arg or "patch"
|
|
139
|
+
return ReleaseOptions(version=version_arg, bump=bump, repository=repository_arg)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _determine_target_version(options: ReleaseOptions) -> str:
|
|
143
|
+
"""Decide the release version based on explicit input or a bump type.
|
|
144
|
+
|
|
145
|
+
'why': ensure both pyproject and package versions stay aligned
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
current = _read_version(_PYPROJECT_PATH, _VERSION_PATTERN)
|
|
149
|
+
_assert_versions_match(current)
|
|
150
|
+
if options.version:
|
|
151
|
+
return options.version
|
|
152
|
+
return _bump_semver(current, options.bump)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _assert_versions_match(expected: str) -> None:
|
|
156
|
+
"""Verify the package and pyproject versions are identical before bumping.
|
|
157
|
+
|
|
158
|
+
'why': prevent partial version updates that ship inconsistent metadata
|
|
159
|
+
"""
|
|
160
|
+
|
|
161
|
+
package_version = _read_version(_PACKAGE_INIT_PATH, _INIT_VERSION_PATTERN)
|
|
162
|
+
if package_version != expected:
|
|
163
|
+
message = " ".join(
|
|
164
|
+
[
|
|
165
|
+
f"Package version mismatch: pyproject.toml has {expected}",
|
|
166
|
+
f"but src/netrias_client/__init__.py has {package_version}",
|
|
167
|
+
]
|
|
168
|
+
)
|
|
169
|
+
raise RuntimeError(message)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _read_version(path: Path, pattern: re.Pattern[str]) -> str:
|
|
173
|
+
"""Extract a version string from `path` using `pattern`.
|
|
174
|
+
|
|
175
|
+
'why': share parsing logic between pyproject and package metadata
|
|
176
|
+
"""
|
|
177
|
+
|
|
178
|
+
text = path.read_text(encoding="utf-8")
|
|
179
|
+
match = pattern.search(text)
|
|
180
|
+
if match is None:
|
|
181
|
+
raise RuntimeError(f"Could not locate version string in {path}")
|
|
182
|
+
return match.group("value")
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _bump_semver(version: str, bump: str) -> str:
|
|
186
|
+
"""Return a new semantic version string incremented by `bump` type.
|
|
187
|
+
|
|
188
|
+
'why': keep release increments predictable without external tooling
|
|
189
|
+
"""
|
|
190
|
+
|
|
191
|
+
major_str, minor_str, patch_str = version.split(".")
|
|
192
|
+
major, minor, patch = int(major_str), int(minor_str), int(patch_str)
|
|
193
|
+
if bump == "major":
|
|
194
|
+
return f"{major + 1}.0.0"
|
|
195
|
+
if bump == "minor":
|
|
196
|
+
return f"{major}.{minor + 1}.0"
|
|
197
|
+
return f"{major}.{minor}.{patch + 1}"
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _update_versions(version: str) -> None:
|
|
201
|
+
"""Write `version` to pyproject.toml and the package __init__ module.
|
|
202
|
+
|
|
203
|
+
'why': guarantee distribution metadata matches the Python package
|
|
204
|
+
"""
|
|
205
|
+
|
|
206
|
+
_replace_version(_PYPROJECT_PATH, _VERSION_PATTERN, f'version = "{version}"')
|
|
207
|
+
_replace_version(_PACKAGE_INIT_PATH, _INIT_VERSION_PATTERN, f'__version__ = "{version}"')
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _replace_version(path: Path, pattern: re.Pattern[str], replacement: str) -> None:
|
|
211
|
+
"""Swap the first version match in `path` with `replacement`.
|
|
212
|
+
|
|
213
|
+
'why': avoid manual editing and keep formatting stable
|
|
214
|
+
"""
|
|
215
|
+
|
|
216
|
+
text = path.read_text(encoding="utf-8")
|
|
217
|
+
updated, count = pattern.subn(replacement, text, count=1)
|
|
218
|
+
if count != 1:
|
|
219
|
+
raise RuntimeError(f"Failed to update version in {path}")
|
|
220
|
+
_ = path.write_text(updated, encoding="utf-8")
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _build_distributions() -> list[Path]:
|
|
224
|
+
"""Build wheel and sdist artifacts and return their paths.
|
|
225
|
+
|
|
226
|
+
'why': provide a clean slate before handing artifacts to verifiers
|
|
227
|
+
"""
|
|
228
|
+
|
|
229
|
+
if _DIST_PATH.exists():
|
|
230
|
+
shutil.rmtree(_DIST_PATH)
|
|
231
|
+
_run_command_or_raise(("uv", "build"))
|
|
232
|
+
return sorted(_DIST_PATH.glob("*"))
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def _verify_artifacts(artifacts: Sequence[Path]) -> None:
|
|
236
|
+
"""Run metadata checks and a local install smoke test for `artifacts`.
|
|
237
|
+
|
|
238
|
+
'why': catch packaging issues before publishing to a remote index
|
|
239
|
+
"""
|
|
240
|
+
|
|
241
|
+
dist_files = [
|
|
242
|
+
path
|
|
243
|
+
for path in artifacts
|
|
244
|
+
if path.suffix == ".whl" or tuple(path.suffixes[-2:]) == (".tar", ".gz")
|
|
245
|
+
]
|
|
246
|
+
if not dist_files:
|
|
247
|
+
raise RuntimeError("No distribution artifacts produced; run `uv build` first")
|
|
248
|
+
_run_command_or_raise(("uv", "run", "twine", "check", *[str(path) for path in dist_files]))
|
|
249
|
+
_smoke_test_artifacts(dist_files)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def _smoke_test_artifacts(artifacts: Sequence[Path]) -> None:
|
|
253
|
+
"""Install the wheel into a temp venv and import the package.
|
|
254
|
+
|
|
255
|
+
'why': validate that the built wheel installs and exposes metadata
|
|
256
|
+
"""
|
|
257
|
+
|
|
258
|
+
wheel = next((path for path in artifacts if path.suffix == ".whl"), None)
|
|
259
|
+
if wheel is None:
|
|
260
|
+
raise RuntimeError("Wheel artifact missing; expected *.whl after build")
|
|
261
|
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
262
|
+
env_path = Path(tmp_dir) / "venv"
|
|
263
|
+
_create_virtualenv(env_path)
|
|
264
|
+
python_path = _resolve_python(env_path)
|
|
265
|
+
if not python_path.exists():
|
|
266
|
+
raise RuntimeError(f"Smoke test interpreter missing: {python_path}")
|
|
267
|
+
_LOGGER.info("smoke test interpreter → %s", python_path)
|
|
268
|
+
_run_command_or_raise((str(python_path), "-m", "pip", "install", str(wheel)))
|
|
269
|
+
_run_command_or_raise((str(python_path), "-c", "import netrias_client as pkg; print(pkg.__version__)"))
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def _create_virtualenv(target: Path) -> None:
|
|
273
|
+
"""Create a fresh virtual environment at `target` with pip installed.
|
|
274
|
+
|
|
275
|
+
'why': isolate smoke tests from the developer environment
|
|
276
|
+
"""
|
|
277
|
+
|
|
278
|
+
_run_command_or_raise(("uv", "venv", str(target), "--seed"))
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def _resolve_python(env_path: Path) -> Path:
|
|
282
|
+
"""Locate the Python executable underneath `env_path`.
|
|
283
|
+
|
|
284
|
+
'why': handle platform differences without duplicating logic
|
|
285
|
+
"""
|
|
286
|
+
|
|
287
|
+
bin_dir = env_path / ("Scripts" if sys.platform == "win32" else "bin")
|
|
288
|
+
candidates = ("python", "python3", "python.exe")
|
|
289
|
+
for candidate in candidates:
|
|
290
|
+
python_path = bin_dir / candidate
|
|
291
|
+
if python_path.exists():
|
|
292
|
+
return python_path
|
|
293
|
+
raise RuntimeError(f"Python executable not found under {bin_dir}")
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def _publish_artifacts(repository: str) -> None:
|
|
297
|
+
"""Publish artifacts to the requested repository via `uv publish`.
|
|
298
|
+
|
|
299
|
+
'why': keep credential handling opinionated yet minimal
|
|
300
|
+
"""
|
|
301
|
+
|
|
302
|
+
if repository not in _REPOSITORY_CONFIG:
|
|
303
|
+
raise RuntimeError(f"Unsupported repository '{repository}'")
|
|
304
|
+
env_var, publish_url = _REPOSITORY_CONFIG[repository]
|
|
305
|
+
token = os.environ.get(env_var)
|
|
306
|
+
if not token:
|
|
307
|
+
raise RuntimeError(f"Set {env_var} before publishing to {repository}")
|
|
308
|
+
command: list[str] = ["uv", "publish", "--username", "__token__", "--password", token]
|
|
309
|
+
display: list[str] = ["uv", "publish", "--username", "__token__", "--password", "******"]
|
|
310
|
+
if publish_url:
|
|
311
|
+
command.extend(["--publish-url", publish_url])
|
|
312
|
+
display.extend(["--publish-url", publish_url])
|
|
313
|
+
_run_command_or_raise(tuple(command), display_command=tuple(display))
|
|
@@ -0,0 +1,222 @@
|
|
|
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.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
netrias_client/__init__.py,sha256=bQ0oTDltyN1IbMZxpo_wQlGqiL3yGkGJD5MKez4PbcI,200
|
|
2
|
+
netrias_client/_adapter.py,sha256=dXJqrpkaAOiZI25gZm0RzFrSFaG4VefvLiM66oI4ziU,9241
|
|
3
|
+
netrias_client/_client.py,sha256=_WVxCOhmCXHG2olDp-eMIKVfHpTt8bibpMQaMRfMSCE,8508
|
|
4
|
+
netrias_client/_config.py,sha256=jY12kLOJ3OMn1YF7QeEq6nU2BaXCpPteoXDz7eprB8I,3098
|
|
5
|
+
netrias_client/_core.py,sha256=f77gwaHfu7lRK2eCSuwumfpU0UXQasZ9D2VVkbPQ68E,18741
|
|
6
|
+
netrias_client/_discovery.py,sha256=YVlA6dGBT4eSUBjyy82aM_Sm_4YK5ulZH_xqk5UJgZk,14380
|
|
7
|
+
netrias_client/_errors.py,sha256=7fdLkoxoz5C55NEFd7ItL8otfJdP1rXsunEAZBzs-VA,960
|
|
8
|
+
netrias_client/_gateway_bypass.py,sha256=dMoEXuDvkGzDnpQ9lYXH6xY8VX-8ghI54-IM-CLQmoA,6441
|
|
9
|
+
netrias_client/_http.py,sha256=h8Kc-8LxIkiRqnKU2RDb4xGf4jdg9jK9bXIH3WDB9xI,4011
|
|
10
|
+
netrias_client/_io.py,sha256=XXIRG5zo1XN_6jk2N8J--czKrOIEeZoAQWzT1Ihgs1M,822
|
|
11
|
+
netrias_client/_logging.py,sha256=5-lhBgp2hWp2K5ZTzz_ZwhJn_sxhSe_t__kdhuMTJnQ,1317
|
|
12
|
+
netrias_client/_models.py,sha256=w_t-rpenLFZiBzLCdRlXaKPqgCrHCjAVoeXjPYF7wIY,1736
|
|
13
|
+
netrias_client/_validators.py,sha256=DvbaQ1Wkf4-W_H5A2PGiC-AxPN2tfpRFpH8vjETGIno,5894
|
|
14
|
+
netrias_client/scripts.py,sha256=jAdREIRbyuSvuvZt6tbRZ9ELfOzQyW9ZQcf2j2HIlsE,11113
|
|
15
|
+
netrias_client-0.0.1.dist-info/METADATA,sha256=5Lx4lh3G_65ThePIeNWWg6W0PHH__8Vg52pJ5hEuMis,9620
|
|
16
|
+
netrias_client-0.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
17
|
+
netrias_client-0.0.1.dist-info/entry_points.txt,sha256=q7Uj2UATtRzlxefJNziCJQ9RXScH8MQzzWvA86Hfytc,162
|
|
18
|
+
netrias_client-0.0.1.dist-info/licenses/LICENSE,sha256=XzmWyunEynTK9hABeKX_9VEd1WcKSDQAM4IXIS-n8WU,1064
|
|
19
|
+
netrias_client-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Netrias
|
|
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.
|