Convert Python ODE systems to SBML (Level 3 Version 2) and PEtab bundles.
ode2sbml is a Python package that converts ordinary differential equation (ODE) systems
written in Python into valid SBML Level 3 Version 2
files and optionally PEtab bundles for parameter estimation.
Installation
pip install ode2sbml
Or install from source:
git clone https://github.com/bibymaths/ode2sbml.git
cd ode2sbml
pip install -e .
Dependencies (installed automatically):
python-libsbml >= 5.20sympy >= 1.12sbmlmath >= 0.3petab >= 0.4click >= 8.0rich >= 13.0numpy >= 1.24pydantic >= 2.0
Quick Start
Convention A — scipy-style function
from ode2sbml import from_function, to_sbml
def lotka_volterra(t, y, p):
x, y_val = y
alpha, beta, delta, gamma = p
dx = alpha * x - beta * x * y_val
dy = -gamma * y_val + delta * x * y_val
return [dx, dy]
model = from_function(
func=lotka_volterra,
state_vars=["x", "y"],
param_names=["alpha", "beta", "delta", "gamma"],
initial_conditions={"x": 10.0, "y": 5.0},
parameter_values={"alpha": 1.1, "beta": 0.4, "delta": 0.1, "gamma": 0.4},
model_id="lotka_volterra",
model_name="Lotka-Volterra",
)
to_sbml(model, "lotka_volterra.xml")
Convention B — dict-of-formulas
from ode2sbml import from_dict, to_sbml
model_spec = {
"species": {"S": 990.0, "I": 10.0, "R": 0.0},
"parameters": {"beta": 0.3, "gamma": 0.1},
"odes": {
"S": "-beta*S*I",
"I": "beta*S*I - gamma*I",
"R": "gamma*I",
},
"compartments": {"host": 1.0},
}
model = from_dict(model_spec, model_id="sir", model_name="SIR Epidemic Model")
to_sbml(model, "sir_model.xml")
Convention C — SymPy symbolic system
import sympy as sp
from ode2sbml import from_sympy, to_sbml
x, y, z = sp.symbols("x y z")
sigma, rho, b = sp.symbols("sigma rho b")
odes = {
x: sigma * (y - x),
y: x * (rho - z) - y,
z: x * y - b * z,
}
params = {sigma: 10.0, rho: 28.0, b: 8.0 / 3.0}
inits = {x: 0.0, y: 1.0, z: 0.0}
model = from_sympy(odes=odes, params=params, inits=inits,
model_id="lorenz", model_name="Lorenz System")
to_sbml(model, "lorenz.xml")
PEtab Export
from ode2sbml import from_dict, to_petab
model = from_dict(model_spec, model_id="sir", model_name="SIR")
yaml_path = to_petab(model, outdir="petab_bundle/", observables={
"obs_I": {"formula": "I", "noise_formula": "0.1 * I"},
})
print(f"PEtab bundle written. Manifest: {yaml_path}")
CLI
# Convert a Python model file to SBML
ode2sbml convert model.py --output model.xml --format sbml
# Convert to PEtab bundle
ode2sbml convert model.py --output ./bundle/ --format petab
# Validate an SBML file
ode2sbml validate model.xml
Supported SBML Features
| Feature | Supported |
|---|---|
| SBML Level 3 Version 2 | ✅ |
| Compartments | ✅ |
| Species (state variables) | ✅ |
| Parameters | ✅ |
| Rate rules (ODEs) | ✅ |
| Assignment rules | ✅ |
| Events (with triggers) | ✅ |
| Unit definitions | ✅ |
| Model notes | ✅ |
| MathML via sbmlmath | ✅ |
| libsbml consistency check | ✅ |
| PEtab bundle export | ✅ |
| JSON serialization (IR) | ✅ |
| Reactions / stoichiometry | ❌ (use RateRules) |
| Spatial SBML | ❌ |
API Reference
Parsers
from_function(func, state_vars, param_names, initial_conditions, parameter_values, ...)— Convention Afrom_dict(model_dict, ...)— Convention Bfrom_sympy(odes, params, inits, ...)— Convention C
Exporters
to_sbml(model, filepath)— Write SBML Level 3 Version 2 XMLto_petab(model, outdir, observables, ...)— Write PEtab bundle
Validators
validate_sbml_file(filepath)— Validate from filevalidate_sbml_string(xml_str)— Validate from stringvalidate_sbml_doc(doc)— Validate libsbml document
IR Classes
ODEModel,Compartment,Species,Parameter,RateRule,AssignmentRule,EventTrigger
References
- Hucka M. et al. (2003). The systems biology markup language (SBML). Bioinformatics.
- Schmiester L. et al. (2021). PEtab. PLOS Computational Biology.
- Müller W. et al. (2021). yaml2sbml. JOSS.
- Watanabe L. et al. (2019). SBMLtoODEpy. JOSS.
- SBML Level 3 Version 2 Specification
- libsbml Python API
- sbmlmath documentation
- PEtab documentation
License
MIT — see LICENSE.
Metadata
Release files for ode2sbml 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ode2sbml-0.1.3.tar.gz | 701.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ode2sbml-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 706.9 kB
Release files / ode2sbml-0.1.3.tar.gz
| Download URL | ode2sbml-0.1.3.tar.gz |
|---|---|
| Size | 701.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a5f6c347b3bd35057d13e3d3d8ac245df275d2f1db2a1179454455d85349ad4
|
|
BLAKE2b-256 checksum How to use checksums |
2b2330d098ec3c71cad2e5b097d20ce6c15588fb74b4e4b535b6eb3f47f991f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 1, 2026.
Transparency logRelease files / ode2sbml-0.1.3-py3-none-any.whl
| Download URL | ode2sbml-0.1.3-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dede688ad42cd4ea16c68b62917cb5f5f30c1f2a8e8960b49169b31fa4f8e684
|
|
BLAKE2b-256 checksum How to use checksums |
0af0f6f996c77326d8faaf6942319dc87ef279361f98dc55e0cd6c0ac6a5335c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 1, 2026.
Transparency log