Skip to main content

ehr2rl

PyPI CI Python

ehr2rl is a Python library for turning MIMIC-IV-style electronic health record data into datasets ready for offline reinforcement learning research.

Healthcare ML libraries are usually built for supervised prediction, while offline RL libraries expect a clean state-action-reward dataset that already exists. ehr2rl fills the gap between those worlds: loading longitudinal EHR tables, representing patient trajectories, shaping rewards, estimating observed behavior, and exporting data for tools such as d3rlpy.

PyPI · GitHub

Features

  • Load and align MIMIC-IV admissions, vitals, and lab tables into patient trajectories.
  • Construct reward signals, including mortality and SOFA delta, with a swappable reward interface.
  • Estimate observed clinician behavior policy from historical data.
  • Export training-ready datasets for offline RL with d3rlpy.
  • Generate synthetic MIMIC-IV-style data for development and testing without credentialed access.

Installation

ehr2rl targets Python 3.10+.

Minimal install:

pip install ehr2rl

For d3rlpy export:

pip install "ehr2rl[d3rlpy]"

Quickstart

Start with synthetic data:

from ehr2rl import make_synthetic_dataset, MortalityReward

ds = make_synthetic_dataset(n_patients=25, trajectory_length=24, seed=7)
ds = MortalityReward().shape(ds)

print(f"Loaded {len(ds)} patient trajectories")
print(f"State shape: {ds.trajectories[0].states.shape}")

Full synthetic-to-d3rlpy round trip:

from ehr2rl import BehaviorPolicy, MortalityReward, make_synthetic_dataset, to_d3rlpy

ds = make_synthetic_dataset(n_patients=25, trajectory_length=24, seed=7)

# v0.1 uses synthetic/user-provided actions. Real medication action construction
# is planned for v0.2.
for trajectory in ds:
    mean_bp = trajectory.states[:, 1]
    trajectory.actions = ((140.0 - mean_bp) / 105.0).reshape(-1, 1)

policy = BehaviorPolicy().fit(ds)
ds = MortalityReward().shape(ds, policy=policy)

# Requires: pip install ehr2rl[d3rlpy]
mdp_dataset = to_d3rlpy(ds)

The synthetic path is the default development path so tests and examples do not require access to MIMIC-IV.

Development Install

pip install -e ".[dev]"
pytest
ruff check .
mypy ehr2rl

MIMIC-IV Access

ehr2rl does not ship, mirror, or provide access to MIMIC-IV. Researchers must obtain any clinical data through the appropriate credentialed channels, such as PhysioNet, and comply with the applicable data use agreements.

Known Limitations

Loader defaults have been spot-checked against MIMIC-IV demo v2.2; full MIMIC-IV v3.1 validation is in progress and targeted for v0.2.

d3rlpy currently prints a Gym deprecation warning under NumPy 2.x; this is an upstream issue and does not affect functionality.

Clinical Disclaimer

ehr2rl is research infrastructure. It is not clinical decision support, does not validate treatment recommendations, and does not define a clinically authoritative reward function. Reward design and interpretation remain the responsibility of the researcher.

Roadmap

v0.2 priorities:

  • Medication-specific action construction.
  • Real MIMIC-IV validation passes beyond the public demo schema.
  • Readmission and composite rewards.
  • Minari export.
  • CLI tooling and a documentation site.
  • Additional dataset families such as eICU, MIMIC-III, and OMOP-CDM.

Contributing

Issues and pull requests are welcome. For v0.1, the most useful contributions are schema checks, synthetic-data edge cases, documentation fixes, and small export compatibility improvements.

If you have access to full MIMIC-IV v3.1 and spot a schema mismatch, opening an issue with the table name and column is especially helpful.

Citation

@software{ehr2rl2026,
  author  = {Bilal Malik},
  title   = {ehr2rl: Bridging MIMIC-IV and Offline Reinforcement Learning},
  year    = {2026},
  version = {0.1.0},
  url     = {https://github.com/pinktownscavenger/ehr2rl}
}

Metadata

Release files for ehr2rl 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 ehr2rl 0.1.0
File Size Uploaded
ehr2rl-0.1.0.tar.gz 16.3 kB Details

Built distribution (wheel)

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

Total release size: 31.1 kB

Release files / ehr2rl-0.1.0.tar.gz

Download URL ehr2rl-0.1.0.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fb658e23e21e05a6ffaee3375e5c89d448115b9ca2abd6588e31518de8d8feae
BLAKE2b-256 checksum
How to use checksums
09559669ff56c61c8813d7a85aaa3d59b162428fe3f213a332feca146442dc87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Jul 30, 2026.

Transparency log

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

Download URL ehr2rl-0.1.0-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a3169269b714edef412b517d5227f947fe36197be8a2ae3fa25b49fc2874486
BLAKE2b-256 checksum
How to use checksums
26f64c959ea63e40295d0cade0f8fcc22504db3a0b19e801579505ef9481d7ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Jul 30, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.1

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

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