Skip to main content
MobsPy logo

MobsPy

Welcome to the Meta-species Oriented Biosystem Syntax in Python repository. MobsPy was invented to facilitate the design of complex Chemical Reaction Networks. In this repository, one can find the first implementation of this language and a simulation tool to simulate models generated by it. The simulation tool has both deterministic and stochastic compatibility.

Python Version

MobsPy requires Python version 3.11 or higher.

Getting started

To get started, you only need to pip install:

pip install mobspy 

And check out the Read the Docs for MobsPy. Tutorial notebooks and example models are available in the docs/example_models/ directory. Install mobspy[examples] for their plotting and notebook dependencies. See example and notebook verification for test commands and CI coverage.

How it works

Meta-species are sets of species. Using them allows users to assign reactions to the entire set or a subset by querying. The Meta-species are based around a reaction inheritance system and independent state spaces.

Basic syntax

To create species from scratch, use the BaseSpecies constructor that takes as an optional argument the number of species one wants to create. To assign rates, use the >> operator and @ for the rate. To assign counts, use the call operator. An elementary example is the following:

from mobspy import *

A, B, C, D = BaseSpecies()
A(200) + B(100) >> 2*C + D @ 420

MySim = Simulation(A | B | C | D)
MySim.run()

Reversible Reactions

Reactions can be reversible by providing a tuple of (forward, reverse) rates:

A(200) + B(100) >> 2*C + D @ (420, 10)

Inheritance

For instance:

Mortal = BaseSpecies()
Mortal >> Zero @ 1

The reaction above is a death reaction where the meta-species Mortal is dying. Zero is the MobsPy variable for representing nothing. We can design new meta-species from other meta-species using either the multiplication or the New() constructor.

Replicator, Triplicator = New(Mortal, 2)
Replicator >> 2*Replicator @ 1
Triplicator  >> 3*Triplicator @ 1
Multiplicator = Replicator*Triplicator 

In the code above, one can visualize the inheritance mechanism. Here both Replicator and Triplicator inherit from Mortal. Therefore, they also receive a death reaction. Multiplicator inherits from Replicator and Triplicator, and therefore from Mortal too. So Multiplicator now has three reactions, the death reaction, the duplication reaction, and the triplication reaction.

Independent State Spaces

Each meta-species has a set of states. One can add states to species by using the dot command (.state) or by inheritance. A meta-species that inherits from another gains access to its states. For instance:

Horned, Color = BaseSpecies()
Horned.small_horn >> Horned.big_horn @ 1
Color.white >> Color.rainbow @ 1
Unicorn = Horned*Color
Unicorn.rainbow >> 2*Unicorn.white @ 1

Unicorn has the states of both Horned and color in the code above and their reactions. Unicorn species will be formed by the name followed by a dot and a state for each species inheritors for all possible combinations. So here we have the species - Unicorn.small_horn.white, Unicorn.big_horn.white, Unicorn.small_horn.rainbow, Unicorn.big_horn.rainbow.

The states can be used in the reactants to assign a reaction only to the correct subset. Here only the rainbow unicorns can duplicate. Finally, the states on the products refer to transformations of states that originate from the same meta-species. So here, all the rainbow Unicorns become white after multiplying since both states come from the meta-species color.

Simulation

Just use the Simulation constructor and the run command to execute a simulation. The Simulation command must receive all the meta-species the user wants to simulate as an argument. For the unicorn example, one could code:

MySim = Simulation(Unicorn)
MySim.run()

Parameter definition

The parameters are defined using the dot notation on the simulation object. For standard parameters, use the dot notation directly, and for plotting parameters, use the .plot_config.parameter notation. See here for a list of parameters. Standard parameters can also be configured using a JSON file with the .set_from_json method. As an example, we have the code below:

MySim.save_data = False
MySim.plot_data = False
MySim.duration = 100
MySim.repetitions = 10
MySim.plot_config.xlim = [0,1]
MySim.plot_config.ylim = [0, 1e3]

For a full list of parameters, see the parameters README.

Units

The variable u from the pint Python module for unit handling is used to assign units to values in MobsPy. Just add u.name_of_the_unit, and MobsPy will handle it. As a code example, we have:

A(100*u.molar)
A >> Zero @ (10 / u.nanosecond)

Compiling

Before simulating, you might want to use the compile method from the Simulation class. The compile function prints all the species, mappings (meta-species and species relation), parameters, and reactions. Thus, allowing one to check their model before simulation and executing.

Calculations

MobsPy generates an SBML string for each model. The SBML string is passed to basiCO (COPASI in Python), and they handle the calculations. MobsPy returns the data to the user in the Simulation object and a JSON file.

For the rates, MobsPy considers mass action kinetics as default. For different, more complex rates, one can use strings.

Compatibility

MobsPy supports defining and compiling models from multiple threads concurrently. Each thread gets isolated DSL state via ContextVar. However, do not share a single Simulation instance across threads.

API Stability

MobsPy follows Semantic Versioning. The public API is everything exported from mobspy.__init__ (listed in __all__):

  • Patch releases (3.0.x) contain bug fixes only.
  • Minor releases (3.x.0) may add new features but will not break existing code.
  • Major releases (x.0.0) may contain breaking changes. These will be documented in the changelog with migration instructions.

Experimental features (such as ODE syntax) are explicitly marked and may change in any release.

See CHANGELOG.md for the full release history, the migration guide for the 3.0 transition, and release instructions for publishing.

Metadata

Release files for mobspy 3.0.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 mobspy 3.0.0
File Size Uploaded
mobspy-3.0.0.tar.gz 446.1 kB Details

Built distribution (wheel)

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

Total release size: 628.6 kB

Release files / mobspy-3.0.0.tar.gz

Download URL mobspy-3.0.0.tar.gz
Size 446.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b48de469e06f88ddb85ddd59bb1f5d079a445c85f4312a57f8c0512e7f414792
BLAKE2b-256 checksum
How to use checksums
a17a84f332f468e0f9ffe7a471a8b897ce2aaffc5b84d5ae65a1070f7a36af1b
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 Sep 16, 2026.

Transparency log

Release files / mobspy-3.0.0-py3-none-any.whl

Download URL mobspy-3.0.0-py3-none-any.whl
Size 182.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
935ed0acc36d307b28d98a1e1a7be2028178cb520328eeff20d61dfc561f15c5
BLAKE2b-256 checksum
How to use checksums
c9e3252ea4b935a1e2d585adde12f9ea9883504c0e53266a7c476d5b920d0d0f
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 Sep 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.8.0

2 release files

2.7.0

2 release files

2.6.1

2 release files

2.6.0

2 release files

2.5.1

2 release files

2.5.0

2 release files

2.4.6

2 release files

2.4.5

1 release file

2.4.4

1 release file

2.4.3

1 release file

2.4.2

1 release file

2.4.1

1 release file

2.4.0

1 release file

2.3.5

2 release files

2.3.4

2 release files

2.3.3

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.2

2 release files

2.0.4

1 release file

2.0.3

1 release file

2.0.2

1 release file

2.0.1

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

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