Skip to main content

suMEDS

PyPI - Version codecov tests code-quality Python Version license PRs contributors DOI MEDS v0.4

suMEDS (pronounced "summed-s", past tense of "sum" + s) creates a compact code catalog for performing tasks Medical Event Data Standard (MEDS) datasets. MEDS data should be "summed" in this way in a storage-efficient format, without the need to access the full dataset.

It can be seen as a form of "extended metadata," as we sometimes need more information than vanilla MEDS metadata provides, but don't want to expose our complete dataset (either because of privacy concerns, storage capacity, or token use efficiency for LLMs). It joins canonical descriptions and configurable parent, child, and sibling codes to event and unique-subject counts, then masks or removes rare codes before writing Parquet, CSV, or JSON.

Polars scans, aggregations, joins, and writes stay lazy. This should mean that it could run with little resources on large MEDS datasets.

Install and run

Normal install:

pip install sumeds

Datasets with more than 2³² rows require Polars' 64-bit runtime:

pip install "sumeds[rt64]"

Development

uv sync
uv run suMEDS tests/resources/MIMICIV_DEMO/MEDS_cohort \
  --output code-summary.parquet \
  --min-subjects 20 \
  --split-columns

Or use YAML:

summary:
  per_split: false
  split_columns: true
  partitions: 256
privacy:
  min_subjects: 20
  min_split_subjects: 1
  rare_code_action: bucket
  rare_code_label: __RARE__
  round_counts_to: 5
uv run suMEDS /path/to/MEDS -o summary.parquet -c examples/summary.yaml
# The suffix selects CSV or JSON instead:
uv run suMEDS /path/to/MEDS -o summary.json -c examples/summary.yaml

CLI flags override YAML. The defaults bucket codes seen in fewer than 20 unique subjects and retain exact counts.

Optionally fill missing descriptions, all ancestors, OMOP concept IDs, domains, and standard-concept markers from OHDSI Athena. Child and sibling expansion are opt-in:

uv run suMEDS /path/to/MEDS -o summary.parquet \
  --athena-csv /path/to/athena --child-codes --child-depth 3 --sibling-codes
# Or use PostgreSQL through the installed psql client:
uv run suMEDS /path/to/MEDS -o summary.parquet \
  --athena-postgres postgresql://postgres@localhost/omop

Standalone enrichment avoids rescanning event data:

uv run suMEDS-enrich metadata/codes.parquet -o codes-enriched.parquet \
  --athena-csv /path/to/athena

The standalone command shows phase progress and reports Athena matches and before/after metadata coverage. Pass the input as -o to enrich it in place, for example a MEDS dataset's metadata/codes.parquet; the input is replaced only once the enriched table is complete.

The VOCABULARY//CODE//..., VOCABULARY//VOCABULARY_VERSION//CODE and OMOP-style VOCABULARY/CODE layouts are resolved, and so is a code's first existing parent reference (ICD9CM/428.0). Every existing parent reference gets its name and its ancestors. See How enrichment works for the steps and a worked example, and Athena enrichment for what is read from Athena, how ICD parents are added, and how Athena compares with the packs.

Rules and public ontology packs

Without Athena, or in addition to it, a sumeds-rules/0.1 file maps dataset codes to vocabulary codes and adds parents that exist in the same table:

schema: sumeds-rules/0.1
ontology:
  - id: icd10cm-diagnoses
    pattern: '^DIAGNOSIS//ICD//10//(?P<code>[A-Z][0-9][0-9A-Z][0-9A-Z]{0,4})$'
    vocabulary: ICD10CM
    normalize: [{pattern: '^(...)(.+)$', replace: '\1.\2'}]
    validate: pack            # pack | athena | none
crosswalk:
  - id: nwicu-lab-loinc
    pattern: '^LAB//(?P<key>[0-9]+)//'
    table: nwicu/loinc_parents
    key_column: itemid
    code_column: loinc_code
    vocabulary: LOINC
hierarchy:
  - {id: eicu-diagnosis-paths, pattern: '^(?P<prefix>DIAGNOSIS//)(?P<path>.+)$', group: path, separator: '|'}
  - {id: icd-prefix, pattern: '^(?P<p>DIAGNOSIS//ICD10_CN//)(?P<code>.+)$', group: code, mode: prefix, ignore: '.'}
  - {id: ontology-parents-in-dataset, from_ontology: true}
uv run suMEDS-enrich metadata/codes.parquet -o codes-enriched.parquet --rules rules.yaml

An ETL package can register its rules file under its MEDS-Extract spec name (entry-point group sumeds.rules), so --rules MC-MED finds it. With MEDS-Extract 0.8.1 or later, its spec can declare the sumeds_enrich stage, and then meds-extract-run alone runs the ETL and enriches its metadata in place:

etl:
  post_stages:
    - sumeds_enrich: {rules: MC-MED}
meds-extract-run spec=MC-MED output_dir=/data/mc_med_meds do_download=false input_dir=/data/mc-med

For other specs, suMEDS-extract runs the ETL and the enrichment in one command, with options for suMEDS-enrich after a --:

suMEDS-extract spec=MC-MED output_dir=/data/mc_med_meds do_download=false input_dir=/data/mc-med

The output's metadata/dataset.json then records the enrichment under sumeds_enrichment: the suMEDS version, the rules and their sha256, the pack release, whether Athena was used, the options, and the coverage before and after. A failed enrichment (for example on a server without internet access) does not fail the ETL: codes.parquet is left as it was, the failure is recorded, and suMEDS-enrich /data/mc_med_meds enriches it later with the recorded rules and options. See Registering rules in a package, Enrich inside a MEDS-Extract ETL, and Recorded in dataset.json.

Codes are validated against ontology packs kept in a separately versioned data repository, sumeds-ontologies. suMEDS fetches them shard by shard on demand from a pinned release tag (default v0.2.0, with the sha256 of its index pinned in suMEDS), verifies every file, and caches it; --offline, --prefetch (fill the cache on a machine with internet access for compute nodes without it) and --ontology-source (a mirror, or packs you rebuilt yourself from the official sources) are supported. Release v0.2.0 holds ICD-10-CM and ICD-10-PCS (FY2016 to FY2027), ICD-9-CM and ICD-9 procedures (v32), which CDC/NCHS and CMS publish without a license agreement (ICD-10-CM and ICD-9-CM adapt WHO classifications, and WHO keeps the copyright in content taken from them), and LOINC 2.83 with its multiaxial hierarchy under the LOINC license. Dataset crosswalk tables (for example lab item ids to LOINC) live there as well. Every added parent comes with its name in parent_names, as the LOINC license asks for LOINC codes; LOINC Parts as parents are opt-in (--loinc-hierarchy). With an Athena download, --no-packs validates rule codes against Athena only. See Rules and ontology packs. Vocabularies that may not be redistributed or whose terms are unknown (SNOMED CT, CPT4, WHO ICD-10, ATC, ...) are validated only through your own Athena download.

This material contains content from LOINC (http://loinc.org). LOINC is copyright © Regenstrief Institute, Inc. and the Logical Observation Identifiers Names and Codes (LOINC) Committee and is available at no cost under the license at http://loinc.org/license. LOINC® is a registered United States trademark of Regenstrief Institute, Inc.

Unit spellings (UCUM)

MEDS ETLs write units as their sources spell them (mg/dl, mg/dL, MG/DL). The sumeds_normalize_units post-stage (or suMEDS-normalize-units) rewrites the unit column of metadata/codes.parquet as canonical, case-sensitive UCUM codes from one shared table, keeping each recorded spelling in unit_source_value. Codes are not changed. ETLs run it after sumeds_link_unit_siblings and before sumeds_enrich:

etl:
  post_stages:
    - sumeds_link_unit_siblings
    - sumeds_normalize_units
    - sumeds_enrich: {rules: <dataset>}

A spelling is rewritten only when every part of it is known (mcg/kg/min is ug/kg/min, °C is Cel, K/uL is 10*9/L); unknown spellings are kept and listed in the log. Case carries meaning (G/l is 10*9/L, g/l is g/L), and words that do not say which unit they mean become annotations (units is {units}, dose is {dose}). sumeds.to_ucum(spelling) gives the mapping itself. See Unit spellings.

Unit siblings

Where an ETL puts the unit in the code because an item has several units (LAB//<item>//mg/dL, LAB//<item>//mmol/L; MEDS-Extract writes one unit per code), the sumeds_link_unit_siblings post-stage (or suMEDS-link-unit-siblings) gives each such code the code without its unit (LAB//<item>) as a parent in parent_codes, and that stem a row of its own: the description and parents its siblings share, and no unit. A code ending in UNK (an unrecorded unit) joins its item's siblings. Options cover how stem descriptions are chosen and units stated in descriptions; it replaces the ETL-local <dataset>_unit_metadata stages. See Unit siblings.

Python API

from sumeds import EnrichmentConfig, SummaryConfig, summarize

path = summarize(
    "/path/to/MEDS",
    "code-summary.parquet",
    SummaryConfig(
        min_subjects=20,
        rare_code_action="bucket",
        enrichment=EnrichmentConfig(csv_dir="/path/to/athena"),
    ),
)

The output format is inferred from .parquet, .csv, or .json (with .jsonl/.ndjson also supported). It preserves all code-metadata extension columns and adds event_count, subject_count, is_static, and is_masked. is_static is true when every event of the code has a null time (a static measurement such as sex), which cohort tools such as ACES only accept as patient demographics; it is null for the rare-code bucket. per_split=True emits one row per split. split_columns=True keeps the total row and adds columns such as event_count_train and subject_count_train from subject_splits.parquet. Set min_split_subjects above 1 to suppress rare split-level cells. numeric_stats=True (CLI --numeric-stats) adds per-code numeric_value statistics: count, mean, median, std, a confidence interval, and trimmed percentiles (5th and 95th by default, each released only when min_subjects subjects lie beyond it), or any subset such as numeric_stats=["mean", "std"]. min and max are opt-in and print a warning: each is one subject's most extreme measurement, which min_subjects does not protect.

Documentation

uv run mkdocs serve
uv run mkdocs build --strict

See the documentation site for the data flow, complete CLI and YAML reference, output schema, Python API, and privacy limitations.

Development

uv run pre-commit run --all-files
uv run pytest
uv run mkdocs build --strict

The included integration test uses tests/resources/MIMICIV_DEMO/MEDS_cohort when present.

Metadata

Release files for sumeds 0.6.7

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

Source distribution (sdist)

Source distribution for sumeds 0.6.7
File Size Uploaded Provenance Actions
sumeds-0.6.7.tar.gz 78.6 kB With provenance Details for sumeds-0.6.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sumeds 0.6.7
File Interpreter ABI Platform Actions
sumeds-0.6.7-py3-none-any.whl Python 3 none any Details for sumeds-0.6.7-py3-none-any.whl

Total release size: 165.9 kB

Release files / sumeds-0.6.7.tar.gz

Download URL sumeds-0.6.7.tar.gz
Size 78.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dd6ef476fdd4ad56fa9bc02d7ce18d4c3a78ed7d037d6c4331e2aa1c0f1f1a9e
BLAKE2b-256 checksum
How to use checksums
38842c365ec371fe0723b12d98c04973084ac16635d8a61a07b18e4f3e951c9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / sumeds-0.6.7-py3-none-any.whl

Download URL sumeds-0.6.7-py3-none-any.whl
Size 87.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0dec1a0d8522589b8d145dd7027f2ae42e8e3b645a8674491966d3a8004ad9c
BLAKE2b-256 checksum
How to use checksums
12e023d6d1a77484a41163c6ea39df5dcbcb42f5d86bb8092482796a53b7f1fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for sumeds 0.6.7

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sumeds-0.6.7.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

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.

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