Skip to main content

openmalaria-nanobind

Minimal Python bindings for OpenMalaria, built with nanobind. Runs a scenario in a fresh subprocess per call and returns pandas DataFrames directly. Bypasses the need to read an XML from the disk, and writing results to the disk.

NOTE: This is NOT a workflow. This repo provides a small and concise way to connect the OpenMalaria C++ code to Python as a library call. This repo does not add additional functionality to OpenMalaria. It is just an environment that provides a consistent way to run OpenMalaria through Python, handle exceptions, and provide small typings for returned information.

Published on PyPI as openmalaria and imported as import openmalaria. Analysis helpers built on top of run() (survey reshaping, age groups, rates) live separately in openmalaria-python (pip install openmalaria-tools, import openmalaria_tools). Everything in this repo is intended as a candidate for upstreaming (see Upstreaming).

Install

This repo depends on the openmalaria C++ core as a git submodule (core/), which is not python-aware. The OM_BUILD_PYTHON CMake flag is built from a local patch here (see patches/)

git submodule update --init
git -C core apply ../patches/0001-add-python-bindings-hook.patch
pip install .

(editable, for development: pip install -e .)

With uv:

git submodule update --init
git -C core apply ../patches/0001-add-python-bindings-hook.patch
uv venv
uv pip install .

(editable: uv pip install -e .)

If core/CMakeLists.txt changes upstream in a way that conflicts with the patch, re-run git -C core apply after resolving and update the patch file (git -C core diff > patches/0001-add-python-bindings-hook.patch).

Usage

import openmalaria as om

result = om.run(path="scenario.xml")
result["survey"]  # pd.DataFrame: survey, column, measure, value
result["continuous"]  # pd.DataFrame (one row per timestep) or None

Or pass scenario XML content directly instead of a file path:

result = om.run(xml=scenario_xml_string, resource_path="/path/to/resources")

NB: schema lookup resolves relative to the current working directory for both path= and xml= (not relative to the scenario file's own directory, if using path=). Run from a directory containing scenario_current.xsd, or otherwise ensure the schema is discoverable from the working directory. Alternatively, pass schema_dir=<dir containing scenario_current.xsd>: the worker subprocess then runs from that directory instead (relative path=/resource_path= are still resolved against the caller's working directory), so the caller never has to chdir.

om.run() also accepts validate_only=True (parse/validate the scenario and stop before any timestep evolution. This acts as a cheap sanity check, equivalent to the CLI's --validate-only), seed=<int> (override the scenario's @iseed), and verbose=True/progress=True (equivalent to the CLI flags of the same name).

Each run() exchanges its input/output with the worker subprocess via pickle files in a temporary directory, which is deleted afterwards by default. tmp_dir=<path> controls where that directory is created (defaults to the system temp dir), and keep_tmp=True skips deletion and prints the kept directory's path to stderr, for inspecting in.pkl/out.pkl after a run.

survey DataFrame schema

Mirrors output.txt's own row schema exactly: survey (1-based survey number), column (encodes age-group/cohort/species/genotype/drug the same way output.txt does), measure (the OutMeasure id), value.

continuous DataFrame schema

One row per reported timestep, one column per enabled monitoring/continuous metric (column names taken from the scenario's own metric titles). None if the scenario has no <continuous> monitoring configured.

Version info

>>> om.version()
{'program_version': 'schema-50.0', 'schema_version': 50}

Equivalent to the CLI's openMalaria --version.

IMPORTANT: one subprocess per run()

OpenMalaria's C++ core keeps several pieces of state as process-global statics that init() functions populate but never clear. This works for the CLI (always exactly one process per scenario), but not for a library function callers might invoke repeatedly in one long-lived process. Verified examples:

  • util::CommandLine::resourcePath -- a 2nd call with resource_path set throws outright ("--resource-path (or -p) may only be given once").
  • util::CommandLine::options -- boolean CLI flags (verbose, progress, ...) leak silently across calls; once set, stuck on for the rest of the process.
  • interventions::InterventionManager -- append-only; throws on a 2nd run reusing any <component id="..."> name, and silently duplicates/accumulates timed and continuous deployments otherwise.
  • Transmission::PerHostAnophParams::params -- append-only per mosquito species; a 2nd run's species indices land on the first run's leftover entries, silently using the wrong entomological parameters.
  • mon::Continuous::toReport -- append-only; a 2nd run's continuous DataFrame would include the first run's columns mixed into its own.
  • mon::internal::runtime.conditions -- push_back-only, never cleared.

It would be ideal to fix the underlying issues with OpenMalaria, but I am not an admin there. So instead, a work around is to launch python -m openmalaria._worker fresh for every call, so there's never a second call in the same still-alive process for any of the above to leak across.

It costs a process-spawn + reimport per run() call

Tests

uv run pytest

tests/test_rerun_consistency.py and test_repeated_calls_in_same_process_succeed guard the one-subprocess-per-run() isolation above: every box-test scenario is run twice in the same process and must match core/test/expected both times.

Linting and type checking

uv run ruff format --check
uv run ruff check
uv run basedpyright

src/openmalaria/_openmalaria.pyi is generated from the compiled module; regenerate it after changing bindings/src/bindings.cpp:

uv run --with nanobind python -m nanobind.stubgen -q -P \
  -p bindings/stubgen_patterns.txt \
  -m openmalaria._openmalaria \
  -o src/openmalaria/_openmalaria.pyi

Limitations

No checkpoint/resume support. Checkpointing (-c/--checkpoint-file on the CLI) remains a CLI-only feature; om.run() exposes no checkpoint parameters.

CPU-core pinning is the caller's responsibility. OpenMalaria's simulation engine has no internal threading (no OpenMP, no std::thread anywhere in the C++ core), so single-core execution is achieved externally: mpirun --bind-to core -np N python script.py, or os.sched_setaffinity(0, {core_id}) (Linux) at the start of a worker process.

Upstreaming

If OpenMalaria adopts Python bindings, this repo maps onto upstream as:

  • patches/0001-add-python-bindings-hook.patch becomes a real OM_BUILD_PYTHON CMake option in upstream's CMakeLists.txt.
  • bindings/ (the nanobind C++ and its CMake) becomes an upstream python/ directory, and src/openmalaria/ its Python package.
  • The core/ submodule and patch step disappear.
  • The subprocess isolation in run()/_worker.py stays until the process-global statics listed above are cleared between runs in the C++ core; after that, run() can call _run() directly.

Release files for openmalaria 0.2.0

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

Built distributions (wheels)

Table of built distributions (wheels) for openmalaria 0.2.0
File
openmalaria-0.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
openmalaria-0.2.0-cp314-cp314-macosx_26_0_arm64.whl CPython 3.14 CPython 3.14 macOS 26.0+ ARM64 Details
openmalaria-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
openmalaria-0.2.0-cp313-cp313-macosx_26_0_arm64.whl CPython 3.13 CPython 3.13 macOS 26.0+ ARM64 Details
openmalaria-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
openmalaria-0.2.0-cp312-cp312-macosx_26_0_arm64.whl CPython 3.12 CPython 3.12 macOS 26.0+ ARM64 Details
openmalaria-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
openmalaria-0.2.0-cp311-cp311-macosx_26_0_arm64.whl CPython 3.11 CPython 3.11 macOS 26.0+ ARM64 Details
openmalaria-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
openmalaria-0.2.0-cp310-cp310-macosx_26_0_arm64.whl CPython 3.10 CPython 3.10 macOS 26.0+ ARM64 Details
openmalaria-0.2.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
openmalaria-0.2.0-cp39-cp39-macosx_26_0_arm64.whl CPython 3.9 CPython 3.9 macOS 26.0+ ARM64 Details

Total release size: 37.3 MB

Release files / openmalaria-0.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL openmalaria-0.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 3.7 MB
Tags CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
d0c60db6931c662dc21829d8a36a9ab00f09354b00b1f199e55f0e04d7790631
BLAKE2b-256 checksum
How to use checksums
9f02062dfa2607920320a4a1359716c8a80a31486598cb81a60a50b9511fa362
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 Sep 25, 2026.

Transparency log

Release files / openmalaria-0.2.0-cp314-cp314-macosx_26_0_arm64.whl

Download URL openmalaria-0.2.0-cp314-cp314-macosx_26_0_arm64.whl
Size 2.6 MB
Tags CPython 3.14 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
b68d68829352eb773f1453d86b88682d4975c213c47456c7c2a63b96ff601bbe
BLAKE2b-256 checksum
How to use checksums
93c97eb6f3fec634bc24fd4e849c89b84becca9f085149c8b4315ce61c3bee0e
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 Sep 25, 2026.

Transparency log

Release files / openmalaria-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL openmalaria-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 3.7 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
49d3a1e9022dcb25fee88e35ebedc1b1a253a15c9d6edd2c29755dfa933845eb
BLAKE2b-256 checksum
How to use checksums
e75fec0e204f7e25bc60e0a18163716bda4749ca5f6431c45c8e2b015acf91ac
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 Sep 25, 2026.

Transparency log

Release files / openmalaria-0.2.0-cp313-cp313-macosx_26_0_arm64.whl

Download URL openmalaria-0.2.0-cp313-cp313-macosx_26_0_arm64.whl
Size 2.6 MB
Tags CPython 3.13 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
8903a6515e9cc912a5094a6393b8432e063272bf612761f0b2fc4e5f321c380f
BLAKE2b-256 checksum
How to use checksums
481411cac75f0f2e9385a2a77dcabb4af8a96514c8bc8e2a49d3edebcc88afc6
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 Sep 25, 2026.

Transparency log

Release files / openmalaria-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL openmalaria-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 3.7 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
8c2e1b8c89b2efabd4e730d31a6849b0cfc8e58e2871a46dec5a800e390d1992
BLAKE2b-256 checksum
How to use checksums
61914e6660de74e4bda366ab0edb35c10b1d9177d44292922118c8269192be48
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 Sep 25, 2026.

Transparency log

Release files / openmalaria-0.2.0-cp312-cp312-macosx_26_0_arm64.whl

Download URL openmalaria-0.2.0-cp312-cp312-macosx_26_0_arm64.whl
Size 2.6 MB
Tags CPython 3.12 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
3e91051414d7f81d9f60b11827e325a57d6f03afaa34e0e9e2525175dfe544d8
BLAKE2b-256 checksum
How to use checksums
f60f6c52a5f012c8c7b81925da04d7b4546affbe4cb5d372fb2910249925f244
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 Sep 25, 2026.

Transparency log

Release files / openmalaria-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL openmalaria-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 3.7 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b82c8badf4e30e986c5a7e092754ba380fd5c2dcf7e566cb19d20d039eca0f51
BLAKE2b-256 checksum
How to use checksums
c89e7e7e64ec59bfc42c441d087cd71f7636504f4ddee110c4c5b15c34006dda
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 Sep 25, 2026.

Transparency log

Release files / openmalaria-0.2.0-cp311-cp311-macosx_26_0_arm64.whl

Download URL openmalaria-0.2.0-cp311-cp311-macosx_26_0_arm64.whl
Size 2.6 MB
Tags CPython 3.11 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
a26dde35fd54b33d7ef7d84d18242fe3f410b431f7d5f575ac3d512fb74f654c
BLAKE2b-256 checksum
How to use checksums
8d50e5c40b57abf4dd11a14389764ba8cb7443df60b3c921f01422ea1b328384
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 Sep 25, 2026.

Transparency log

Release files / openmalaria-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL openmalaria-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 3.7 MB
Tags CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
dfb402032e6c9f1b6cfa8db1f6154137e0b7310df054e9bce56e1783b11cc971
BLAKE2b-256 checksum
How to use checksums
3ea7d914b60ea80e824dfc2811b0a2ef30c478464f8c44422d53a03b7a51f3cb
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 Sep 25, 2026.

Transparency log

Release files / openmalaria-0.2.0-cp310-cp310-macosx_26_0_arm64.whl

Download URL openmalaria-0.2.0-cp310-cp310-macosx_26_0_arm64.whl
Size 2.6 MB
Tags CPython 3.10 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
53978273ffc319a75858dd5bfcd8c56b54ed673ddd9f5e49b531330b90112906
BLAKE2b-256 checksum
How to use checksums
5482d07d2f58b82b9f281d343872585507c102329ff962c5c5c10bb254fb214c
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 Sep 25, 2026.

Transparency log

Release files / openmalaria-0.2.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL openmalaria-0.2.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 3.6 MB
Tags CPython 3.9 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
7ce85076649f19f08880744de81ac2e7ac6b2ae451d599541f1cd01cd9fc495c
BLAKE2b-256 checksum
How to use checksums
123354f21793ce6c5c399caa86ac295cf5a51e18c348c6651acd77178292da76
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 Sep 25, 2026.

Transparency log

Release files / openmalaria-0.2.0-cp39-cp39-macosx_26_0_arm64.whl

Download URL openmalaria-0.2.0-cp39-cp39-macosx_26_0_arm64.whl
Size 2.6 MB
Tags CPython 3.9 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
9ec8770794df1d66494fdacd2def6b1bceaa133cc499ca9e427cc0800691e999
BLAKE2b-256 checksum
How to use checksums
9ccb2a1630add6cdef94fc46992b9a2fa2d4fb805f7e3a878c33d0bb6326fe34
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 Sep 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

12 release files

0.1.0

12 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