Skip to main content

LHM — Longevity Health Metrics SDK

One plain-English question about your own health data → a claim-safe, uncertainty-carrying personal metric → published to your dashboard.

from syntropy import lhm

result = await lhm.ask(
    "How does my magnesium intake relate to my sleep quality?",
    adapter=my_data,            # your data, your process — nothing leaves it
    interpreter=my_llm,         # bring your own LLM (or skip NL entirely)
)
result.suggestions                    # tiered candidates: low / mid / strong
await result.publish(my_dashboard)    # → your syntropy-journal dashboard

That's the whole loop: language → analysis → metric suggestions → publication. Your inputs (supplements, food, regimen starts) and outcomes (journal series, wearables, check-ins) are mapped onto standard FHIR resources, analyzed as a single-subject observational series with named statistical corrections, tiered, gated for claim-safety, and pushed to a dashboard you own.

The honesty layer is structural, not prose. Every metric is a personal correlation/trend — never a causal, treatment, or clinical claim. The claim-scope guard (syntropy.lhm.metrics.claims.assert_claim_safe) gates every persist, publish, and render: banned clinical-efficacy vocabulary fails loudly, and a metric cannot exist without its uncertainty caveats.

Install

pip install syntropy-lhm                # core: clinical mapping + pipeline + contracts
pip install "syntropy-lhm[units]"       # + UCUM quantity validation (pint/ucumvert)
pip install "syntropy-lhm[publish]"     # + the HTTP publisher (httpx transport)

# pip install "syntropy-lhm[stats]"     # v2 — not yet published; the numerical-
#                              # estimator extra ships with the v2 estimators
#                              # (see the roadmap below). Installing it today
#                              # would fail: the extra does not exist yet.

Core stays lean by design: fhir.resources (typed FHIR R4B, pydantic v2) and nothing else — no web framework, no ORM, no LLM, no network I/O.

How it works

"How does my magnesium relate to my sleep?"
      │
      ▼  Interpreter (BYO-LLM — optional; every step below is typed & callable directly)
MetricIntent(input="magnesium", outcome="sleep quality", window=90d)
      │
      ▼  fetch(adapter, user)         # your data → FHIR-mapped, time-aligned series
AlignedData(regimen start marked, rx-tier flagged)
      │
      ▼  analyze(aligned)             # six named n-of-1 corrections, tier surface
CandidateSignal(tier=mid, interval, corrections, caveats)
      │
      ▼  manage("add", candidate)     # the R10 claim gate — banned lexicon fails here
MetricSpec + VizPayload               # the persistence + render contracts
      │
      ▼  publish(target)              # self-hosted journals, or cloud w/ API key
your dashboard

The NL layer is sugar, never load-bearing. Every stage consumes and returns typed models you can construct by hand — syntropy.lhm.ask() is a convenience composition, not a magic box. The LLM only narrows language to a MetricIntent; the SDK binds it to your actual data deterministically, so a hallucinated column can't silently become a metric.

Bring your own data (the only required integration)

Implement three async readers — that's the whole adapter contract:

class MyAdapter:
    async def read_orders(self, user_scope): ...          # → [OrderRecord]
    async def read_regimen_starts(self, user_scope): ...  # → [RegimenStartRecord]
    async def read_outcome_series(self, user_scope): ...  # → [SeriesRecord]

CSV, SQLite, a wearable export, a full app backend — anything that can fill those records. user_scope is an opaque token you choose; LHM never sees a name, email, or free-text note (check-in notes reach it only as an in-boundary sentiment float you derive).

Publish: self-hosted first, cloud by API key

The publish contract (lhm-publish/v1) is ONE versioned envelope — MetricSpec + VizPayload + an idempotency key — POSTed to a syntropy-journal backend:

from syntropy.lhm import SyntropyTarget

# Self-hosted: your own syntropy-journal instance
target = SyntropyTarget(base_url="https://journal.my-lab.dev")

# Cloud (commercial): the SAME contract — an API key is the only delta
target = SyntropyTarget(
    base_url="https://app.syntropyhealth.bio",
    api_key=os.environ["SYNTROPY_API_KEY"],     # never persisted by the SDK
)

receipt = await result.publish(target)
receipt.dashboard_url                            # deep link to the rendered card

Publishing is idempotent (at-least-once safe), claim-gated before transport, and Rx-tier metrics structurally refuse public surfaces. The SDK never stores your key (it is held as a SecretStr — masked in repr and every model_dump).

Targets must be https:// — the API key rides a header, and plain http would send it in cleartext. Plain http is accepted only for loopback dev hosts (localhost / 127.0.0.1 / [::1]); anything else needs an explicit SyntropyTarget(..., allow_insecure=True) opt-in. If you publish in-process instead of over HTTP, InProcessPublisher(callback, public_surface=...) requires the surface declaration — there is no default.

Status & roadmap

Layer What Status
L0 — contracts MetricSpec, lhm-viz/v1 schema, claim-scope guard ✅ shipped
L1 — clinical mapping orders/regimens/series → FHIR R4B; synthetic fixtures; PHI/secret gates ✅ shipped
L2 — pipeline v0.1 fetch → analyze → manage; six correction hooks (contract-tested stubs); tier surface ✅ shipped
L3 — journals adoption reference adapters, dashboard binding, the /api/lhm/v1/metrics route ✅ shipped
L4 — NL + publish syntropy.lhm.nl (MetricIntent, Interpreter, resolve_intent), syntropy.lhm.publish (envelope, targets, publishers), syntropy.lhm.ask ✅ shipped — design 0001
L4 — docs pillar app-independent guide tree (docs/), execution-verified examples ✅ shipped
L4 — packaging the D13 repo split + PyPI publish 🔜 next
v2 — real estimators syntropy-lhm[stats]: AR(1)/detrend/ITS/posterior + FDR in the six hooks; ratified tier cutoffs 📐 hooks in place
cloud — hosted dashboard API-key issuance, workspaces, the commercial surface 🗺 vision

Packaging: LHM lives in the syntropy-journal repo through L3 (maximum- coupling build phase), then splits to its own repo + PyPI at L4 so pip install syntropy-lhm is real and the app consumes it like any dependency — decision record: design 0002.

v0.1 proves shapes and plumbing; the deterministic stubs make every contract testable today. The full design for the NL→publish pipeline — use cases, dependency tiers (numerical / clinical / models), the publish data models, and the API-key semantics — lives in docs/design/0001-nl-to-publish-pipeline.md. Full guides — quickstart, adapters, NL & syntropy.lhm.ask, publishing, the honesty layer, and the error reference — live at docs/README.md.

Design principles

  • App-independent: bring your own adapter, LLM, and render surface. (Syntropy's journal app is the first consumer, not a dependency.)
  • Clinical models, not bespoke schemas: FHIR R4B via fhir.resources.
  • Versioned contracts: lhm-viz/v1 (render) and lhm-publish/v1 (transport) — additive-only within a version; JSON schemas ship in the package.
  • Privacy-blind by construction: in-process data only; no payload logging; opaque subject tokens; all bundled fixtures synthetic (scan-gated in CI).
  • Honest by construction: correlation language, uncertainty intervals, verbatim caveats, and a lexicon gate that fails the build — not a disclaimer paragraph.

Quickstart (v0.1 — the shapes that already run)

from syntropy.lhm import InputRef, MetricSpec, OutcomeRef, to_viz_payload, VizPoint

spec = MetricSpec(
    metric_key="mag_sleep",
    label="Magnesium intake and sleep quality — personal trend",
    inputs=(InputRef(resource="NutritionOrder", code="supplement-order",
                     display="Magnesium glycinate"),),
    outcome=OutcomeRef(kind="journal_series", series_key="sleep_quality"),
    confidence="mid",
    caveats=(
        "Personal n-of-1 association from your own records — observational, not causal.",
        "Estimates carry an uncertainty interval and may not generalize.",
    ),
    rx_input=False,
)
payload = to_viz_payload(spec, series=[VizPoint(ts=..., value=...)])  # render-gated

And the L2 pipeline end-to-end against synthetic data:

from syntropy.lhm.fixtures import synthetic_order, synthetic_regimen_start, synthetic_series
from syntropy.lhm.tools import analyze, fetch, manage

aligned = await fetch(my_adapter, "subject-001")
signals = await analyze(aligned)                  # tiered, corrections-threaded
outcome = await manage("add", signals[0])         # claim-gated, persistence-ready
outcome.parameterization                          # the C4 JSONB your store persists

License

Apache-2.0. Runtime dependencies are BSD/MIT-family only (attributions in NOTICE); no copyleft in the graph, re-verified at every release. All example data is synthetic.

Metadata

Release files for syntropy-lhm 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for syntropy-lhm 0.1.0
File Size Uploaded Provenance Actions
syntropy_lhm-0.1.0.tar.gz 101.2 kB Without provenance Details for syntropy_lhm-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for syntropy-lhm 0.1.0
File Interpreter ABI Platform Actions
syntropy_lhm-0.1.0-py3-none-any.whl Python 3 none any Details for syntropy_lhm-0.1.0-py3-none-any.whl

Total release size: 170.4 kB

Release files / syntropy_lhm-0.1.0.tar.gz

Download URL syntropy_lhm-0.1.0.tar.gz
Size 101.2 kB
Tags Source
SHA-256 checksum
How to use checksums
fff6beb3ae4efdd228432cabb0e3ec79f341c02374951c741ce2ba5fbab1830e
BLAKE2b-256 checksum
How to use checksums
fb517115edbe60928e7a15ef462090b928d8c5d4a29279100e1f7510e549436e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / syntropy_lhm-0.1.0-py3-none-any.whl

Download URL syntropy_lhm-0.1.0-py3-none-any.whl
Size 69.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ba2432c52826a58f111728075f6aadbcbbaa2dfdd85c9163264ffaca18a73f4
BLAKE2b-256 checksum
How to use checksums
dbd4b18a820360b8f31764ebbf5d1d04a765ba24ffbe3d69225452a479e1db84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Security for syntropy-lhm 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page