Lab unit converter for developers
Lab data arrives as mg/dL and mmol/L, µg/L and ng/mL, written a dozen ways. lifefrom-units normalises the spelling, converts with factors that each cite their source, and refuses the conversions that look valid but aren't. 452 unit spellings, 83 tests with sourced conversions, Python and TypeScript sharing one set of test cases.
Use it in code
# Python
# pip install lifefrom-units
from lifefrom_units import convert
convert(99, "mg/dL", "mmol/L", analyte="glucose")
// TypeScript
// npm install @lifefrom/units
import { convert } from "@lifefrom/units";
convert(99, "mg/dL", "mmol/L", "glucose");How it was built
Factors that follow from the units alone (mg/L to µg/mL) are derived. Factors that depend on the substance (glucose mg/dL to mmol/L) use its molar mass from PubChem or a published conversion table, named for each factor. Pairs that measure different things, like Lp(a) by mass and by particle count, are refused with the reason.
Both packages run the same test vectors: round trips, spelling variants, decimal commas and every refused pair.
Download
Code, data and tests: github.com/caraulani/lifefrom-units
Archived on Zenodo: doi.org/10.5281/zenodo.24543312
- analyte_factors.csv (16 KB)
- release1_comparison.csv (26 KB)
- units.json (0.2 MB)
- README.md (16 KB)
- METHODS.md (22 KB)
- CITATION.cff (2 KB)
- LICENSE (3 KB)
- CHANGELOG.md (3 KB)
- SHA256SUMS (5 KB)
Cite
LifeFrom (2026). lifefrom-units: lab unit conversion you can check, version 1.0.0. lifefrom.ai/research/open-data/lab-units. https://doi.org/10.5281/zenodo.24543312