What if you could create a human being inside your computer — not a 3D avatar, but a physiological one? A body with a beating heart whose blood pressure responds to blood loss, lungs that desaturate at altitude, a pancreas that releases insulin after a meal, and an immune system that can tip into sepsis?
That's humanbody: a single Python object you step forward in time.
from humanbody import HumanBody
body = HumanBody()
for _ in range(60): # 60 seconds of life
body.step(dt=1.0)
print(body.state_summary())
# HR=72, MAP=93, PaO2=97, SaO2=0.98, glucose=94, cortisol=15, pH=7.40 ...
Every number that comes out of state_summary() is the emergent result of dozens of coupled differential equations — not a lookup table. Change one thing (bleed the patient, feed them, send them up a mountain) and the whole body responds the way a real body would.
It's 255 tests of mathematical physiology, and it's open source.
🔗 Code: github.com/cosmosoneness/Cosmos (under
Emulation/Human_Body/)
Why build this?
Textbooks teach physiology one system at a time: here's the cardiac cycle, here's the nephron, here's the HPA axis. But the body isn't a list of chapters — it's a giant feedback network. When you exercise, your muscles demand oxygen, which raises your heart rate, which the baroreflex modulates, which shifts your blood pressure, which changes kidney filtration, which adjusts your fluid balance… all at once.
I wanted to feel those couplings, not just read about them. The only way to really understand a control system is to build one and watch it misbehave.
So I built the whole thing — fourteen phases, from molecules up to clinical scenarios.
The architecture: thinking in scales
The model is organized by biological scale, and the dependency arrow always points up:
molecular → enzyme kinetics, Hill dissociation, ATP/PCr/lactate
cellular → Hodgkin–Huxley ion channels, membrane potential
tissue → Krogh-cylinder oxygen diffusion
systems/ → 9 organ systems (the meat)
integration → HumanBody aggregator + homeostasis
scenarios → clinical challenges you can run
The nine organ systems each implement well-known models from the literature:
| System | Model |
|---|---|
| Cardiovascular | Suga–Sagawa time-varying elastance + Ursino Windkessel + baroreflex |
| Respiratory | Otis–Rohrer mechanics + alveolar gas equation + Hill O₂ dissociation |
| Nervous | Wilson–Cowan cortical mass + brainstem rhythm generator + autonomic tone |
| Endocrine | HPA / HPT / HPG axes + Dalla Man glucose–insulin + ADH/RAAS |
| Digestive | 5-compartment GI transit + liver glycogen + microbiome SCFA |
| Renal | glomerulus + tubular handling + countercurrent multiplier + acid–base |
| Musculoskeletal | Hill-type muscle + PCr/lactate buffering + Lemaire bone remodeling |
| Integumentary | Gagge two-node thermal model |
| Immune | innate + adaptive + Perelson pathogen dynamics + SIRS criteria |
They talk to each other through a shared signal bus — a dictionary of cross-system variables like mean arterial pressure, arterial oxygen, glucose, and cortisol — plus an event bus for discrete events like "a meal was eaten."
The hard part: time
Here's the thing nobody tells you about whole-body simulation — different systems live on wildly different timescales.
The heart beats on the order of milliseconds. A cardiac action potential, valve dynamics, the pressure pulse — all of it is stiff. Meanwhile, your cortisol rhythm plays out over hours, and bone remodeling takes weeks.
My first integration attempt used a naive forward-Euler step at dt = 1 second for everything. The result? Mean arterial pressure exploded to 5 × 10⁴⁹ mmHg. The cardiac ODE was catastrophically unstable at that step size.
The fix was per-system substepping: inside one body.step(dt=1.0), the engine runs the heart and circulation at 1 ms substeps (1000 iterations), the respiratory pump at 50 ms substeps, and everything slower at the full dt.
def step(self, dt=1.0, **perturbations):
# Cardiac dynamics are stiff — substep finely
n_cardio = max(1, int(dt / 1e-3))
for _ in range(n_cardio):
self.cardio.step(1e-3, signal=self.signal)
# Respiratory — medium substep
n_resp = max(1, int(dt / 0.05))
for _ in range(n_resp):
self.respiratory.step(0.05, signal=self.signal)
# Slow systems — one macro step
self.endocrine.step(dt, signal=self.signal)
self.renal.step(dt, signal=self.signal)
self.bus.publish(TickEvent(time=self.t, source="body", dt=dt))
This is the same idea as multi-rate integration in circuit simulators. It's not glamorous, but it's the difference between a model and a number that overflows a float.
Watching it come alive: clinical scenarios
The payoff is the scenario framework. Seven clinical challenges ship built-in:
from humanbody.scenarios import HemorrhageScenario, run_scenario
result = run_scenario(HemorrhageScenario(volume_mL=1000), dt=1.0)
print(result.alerts)
# ['Shock: MAP < 65 mmHg']
Run the hemorrhage scenario and you watch the baroreflex fight to maintain pressure as a liter of blood drains away — heart rate climbs, then pressure finally collapses into shock and the homeostasis monitor raises an alert.
Run sepsis and IL-6 rises, drives a fever and tachycardia, and the system checks itself against the actual SIRS criteria.
Run high-altitude and the barometric pressure drop propagates through the alveolar gas equation into the Hill oxygen-dissociation curve — SaO₂ falls, the chemoreflex kicks in, and ventilation rises.
Run diabetic ketoacidosis and glucose stays sky-high while bicarbonate falls and the pH drops below 7.3.
Each scenario is just a small class — and writing your own takes about a dozen lines:
from humanbody.scenarios.clinical import Scenario
class CaffeineDose(Scenario):
"""200 mg caffeine -> tachycardia + higher cortisol."""
def __init__(self):
super().__init__(name="Caffeine",
description="200 mg single dose",
duration=3600.0)
self.applied = False
def step_perturbation(self, body, t):
if not self.applied and t >= 60:
body.endocrine.hpa.stress_input += 0.2
body.cardio.baroreflex.set_point += 5
self.applied = True
return {}
What it can — and can't — do
Let me be honest about the boundaries, because that matters more than the demo.
It's good for: teaching integrated physiology, prototyping clinical scenarios, "what-if" experiments, and as a scaffold you can subclass into something research-grade. You learn an enormous amount just by breaking it.
It's not: a medical device, a source of patient-specific predictions, or publication-grade quantitative biology. Every ODE is forward-Euler with substepping — accurate enough to be qualitatively right, not quantitatively certified. Do not use it for medical decisions.
There's also a fun gotcha I left in the docs: ask for blood pressure at the wrong instant and you might see "MAP = 8.9 mmHg." That's not a bug — it's the instantaneous pressure sampled at diastole. The cardiac ODE is genuinely pulsatile at 1 ms resolution, so you have to average over a cycle to get a textbook number. The model is more honest than the summary statistic.
The bigger project
humanbody is actually one chapter of a larger repo I'm calling the Cosmos Research Institute — an umbrella for end-to-end "emulators" of real systems, from a cellular artificial-life world to connectome-level whole-brain emulation. The ambition is to keep building computational models of the world we live in until the name stops being a joke.
But you have to start somewhere, and the body is a beautiful place to start: it's the most sophisticated control system any of us will ever own, and now there's a version of it you can pip install and break to your heart's content.
Try it
git clone https://github.com/cosmosoneness/Cosmos.git
cd Cosmos/Emulation/Human_Body
pip install -e ".[dev]"
pytest tests/ -q # 255 passed
humanbody run exercise --duration 600
humanbody serve --port 8000 # REST API
- 🔗 Source: github.com/cosmosoneness/Cosmos
- 📖 Tutorial: the
TUTORIAL.mdin the repo has seven hands-on walkthroughs - ⭐ If it teaches you something, a star helps others find it
Built in Python with the help of Claude Code. The individual modules credit the papers they implement — Suga & Sagawa, Ursino, Dalla Man, Wilson & Cowan, Lemaire, Gagge, Perelson, and many others whose mathematical physiology made this possible.

Top comments (0)