Skip to main content

Python client for the Netrias harmonization API

Project description

Netrias Client

"""Explain how to install and exercise the Netrias harmonization client."""

Install with uv

  • Install uv once (or update): curl -LsSf https://astral.sh/uv/install.sh | sh
  • Sync dependencies for a project that consumes the client:
    uv add netrias_client
    uv add python-dotenv  # optional helper for loading .env files
    
  • Prefer uv run <command> for executing scripts so the managed environment is reused automatically.

Alternative: pip

python -m pip install netrias_client
python -m pip install python-dotenv  # optional

Quickstart Script

Reference script (save as main.py) showing a full harmonization round-trip:

#!/usr/bin/env -S uv run python
# /// script
# requires-python = ">=3.13"
# dependencies = ["netrias_client", "python-dotenv"]
# ///

"""Exercise the packaged Netrias client against the live APIs."""

import asyncio
import os
from pathlib import Path
from typing import Final

from dotenv import load_dotenv
from netrias_client import NetriasClient, __version__ as CLIENT_VERSION

load_dotenv(override=True)

CSV_PATH: Final[Path] = Path("data/primary_diagnosis_1.csv")


async def main() -> None:
    client = NetriasClient()
    client.configure(api_key=_resolve_api_key())

    manifest = client.discover_cde_mapping(
        source_csv=CSV_PATH,
        target_schema="ccdi",
    )

    result = await client.harmonize_async(
        source_path=CSV_PATH,
        manifest=manifest,
    )

    print(f"netrias_client version: {CLIENT_VERSION}")
    print(f"Harmonize status: {result.status}")
    print(f"Harmonized file: {result.file_path}")


def _resolve_api_key() -> str:
    api_key = os.getenv("NETRIAS_API_KEY")
    if api_key:
        return api_key
    msg = "Set NETRIAS_API_KEY in your environment or .env file"
    raise RuntimeError(msg)


if __name__ == "__main__":
    asyncio.run(main())

Steps

  1. Install or update uv (see above).
  2. Export NETRIAS_API_KEY (or add it to a local .env).
  3. Adjust CSV_PATH to point at the source CSV you want to harmonize.
  4. Run uv run python main.py.

configure() Options

NetriasClient.configure(...) accepts additional tuning knobs. You can mix and match the ones you need:

Parameter Type Purpose
api_key str Required. Bearer token for authenticating with the Netrias services.
timeout `float None`
log_level `LogLevel str
confidence_threshold `float None`
discovery_use_gateway_bypass `bool None`
log_directory `Path str

Configure only the options you need; unspecified values fall back to sensible defaults.

Usage Notes

  • discover_cde_mapping(...) samples CSV values and returns a manifest-ready payload; use the async variant if you’re already in an event loop.
  • 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.
  • The package exposes __version__ so callers can assert the installed release.
  • Optional extras (netrias_client[aws]) add boto3 helpers for the temporary gateway bypass.

Data Model Store (Validation)

Query reference data for validation use cases:

from netrias_client import NetriasClient

client = NetriasClient()
client.configure(api_key="...")

# List available data models
models = client.list_data_models()

# List CDEs for a model version
cdes = client.list_cdes("ccdi", "v1")

# Validate a value against permissible values
is_valid = client.validate_value("Male", "ccdi", "v1", "sex_at_birth")

# Or get the full PV set for repeated lookups
pv_set = client.get_pv_set("ccdi", "v1", "sex_at_birth")
assert "Male" in pv_set

All methods have async variants (list_data_models_async, validate_value_async, etc.).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netrias_client-0.1.0.tar.gz (29.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

netrias_client-0.1.0-py3-none-any.whl (36.4 kB view details)

Uploaded Python 3

File details

Details for the file netrias_client-0.1.0.tar.gz.

File metadata

  • Download URL: netrias_client-0.1.0.tar.gz
  • Upload date:
  • Size: 29.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for netrias_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a3c9603d1bf2ee5b6cabad5292872284371106ba480c32f058ed3672926a3ee4
MD5 85a78249fd45e4c58788d58910c4cafd
BLAKE2b-256 71a06ccb1bc932b7e6f1d6973f8808ce1df67b713c6bab224880e6c82e7f2397

See more details on using hashes here.

File details

Details for the file netrias_client-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for netrias_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2fa268b710506df79ff3930f975b85e5b5f713b9c889a668d5b416ef247110b6
MD5 88bb7afa73866f44ed187ba1580ceaf0
BLAKE2b-256 645e402cd2d3aea4fe626eca0621c29930610e5ce932fa3b86bc2a0ed68cb2d8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page