Skip to main content

Mosaik API for Python

This is an implementation of version 3 of the mosaik API for simulators written in Python. It hides all the messaging and networking related stuff and provides a simple base class that you can implement.

Installation

Just use pip to install it:

$ pip install mosaik-api-v3

Documentation

Please refer to mosaik’s documentation of the API.

Example Simulator

This distribution contains an example simulator in the example_sim package.

It can be started via the pyexamplesim command; pyexamplesim --help shows you how to use it.

It can also be run in-process by importing and calling example_sim.mosaik.main().

Example MAS

This distribution contains an example “multi-agent system” that uses the asyncronous remote calls to mosaik (get_progress(), get_related_entities(), get_data(), set_data()).

It can be started via the pyexamplemas command; pyexamplemas --help shows you how to use it.

It can also be run in-process by importing and calling example_mas.mosaik.main().

Development setup

To setup a devleopment environment, create a virtualenv and install the packages from requirements.txt:

$ mkvirtualenv --python=/usr/bin/python3 mosaik-api-python
(mosaik-api-python)$ pip install -r requirements.txt

To run the tests for the Python version you are currently using, execute py.test. You should also add the test coverage check:

(mosaik-api-python)$ py.test --cov=example_mas --cov=example_sim --cov=mosaik_api_v3

To run the tests for all supported Python versions, run tox:

(mosaik-api-python)$ tox

Mosaik’s documentation contains more details.

Changelog

3.0.16 - 2026-08-25

  • [FIX] Simulators using Python’s script entrypoint now work when used in a directory with spaces in the path.

3.0.15 - 2026-06-18

  • [CHANGE] Replace unmaintained docopt dependency by docopt-ng.

3.0.14 - 2025-10-07

  • [NEW] Introduce the run_as_client and run_as_server functions to run simulators as part of larger programs. Unlike start_simulation, these functions don’t provide their own command-line interface and take the necessary settings as parameters.

3.0.13 - 2024-12-11

  • [CHANGE] The finalize method is now called before the connection to mosaik is closed.

3.0.12 - 2024-08-19

  • [FIX] Remote exceptions occurring during calls to mosaik are now correctly reported to the calling simulator.

3.0.11 - 2024-07-17

  • [CHANGE] Set default logging level back to info

  • [NEW] configure_logging flag on start_simulation to control automatic logger setup

3.0.10 - 2024-05-17

  • [CHANGE] Simulators return a stacktrace to mosaik when running into an exception

  • [FIX] Type for ModelDescription was missing fields

3.0.9 - 2024-03-28

  • [CHANGE] We don’t overwrite the logging system in start_simulation anymore, except when the user explicitly sets –log-level on the command line. This also changed the default level to debug.

3.0.8 - 2024-03-25

  • [FIX] Enable yielding coroutines in finalize

3.0.7 - 2023-12-19

  • [FIX] Make example_sim’s meta legal

3.0.6 - 2023-12-13

  • [FIX] Close asyncio.StreamWriters properly

3.0.5 - 2023-11-08

  • [CHANGE] Improve typing support: package is marked with py.typed file, types are exported from mosaik_api_v3, Meta and CreateResult are split into optional and required fields

3.0.4 - 2023-08-31

  • [NEW] Use loguru for logging

  • [CHANGE] Remove simpy.io

3.0.3 - 2022-12-14

  • [NEW] Add datetime utility

3.0.2 - 2022-06-01

  • [CHANGE] Use internal mosaik-simpy-io>=0.2.4 instead of simpy.io

3.0.1 - 2022-04-22

  • [CHANGE] Set external events via highlevel function call

3.0.0 - 2021-05-02

  • [CHANGE] Added time_resolution to init function

  • [CHANGE] Added max_advance to step function

  • [NEW] Implemented set_events capability (external events)

2.4.2 - 2020-11-24

  • [FIX] Constrain simpy to version <4 due to simpy.io incompatibility

2.4 - 2019-02-05

  • [NEW] Simulator can now be started on a different node than mosaik, using the remote flag “-r” and the timeout flag “-t”. Mosaik can the integrate the simulator using the “connect” method of the simmanager.

2.3 – 2019-01-24

  • [BugFix] Bugfix Tests

2.2 – 2016-02-15

  • [NEW] API version 2.2: Added an optional “setup_done()” method.

  • [CHANGE] API version validation: The API version is no longer an integer but a “major.minor” string. The major part has to math with mosaiks major version. The minor part may be lower or equal to mosaik’s minor version.

  • [FIX] Various minor fixes and stability improvements.

2.1 – 2014-10-24

2.0 – 2014-09-22

  • Initial release of the mosaik 2 Sim API for Python.

Authors

The original concepts for the mosaik API were developed by Steffen Schütte and Stefan Scherfke.

The author of the mosaik API version 2 is Stefan Scherfke.

The author of the mosaik API version 3 is Thomas Raub.

Additional contributors: André El-Ama, Okko Nannen, Annika Ofenloch, Thomas Raub, Eike Schulte, Jan Sören Schwarz, Cornelius Steinbrink

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mosaik_api_v3-3.0.16.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mosaik_api_v3-3.0.16-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file mosaik_api_v3-3.0.16.tar.gz.

File metadata

  • Download URL: mosaik_api_v3-3.0.16.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mosaik_api_v3-3.0.16.tar.gz
Algorithm Hash digest
SHA256 64881fbe735fbd3db0601a971937806e2c8f4a852755c1f6c9b815812e011eb2
MD5 8e3d07314228f3f5ae4403f17e029c12
BLAKE2b-256 3e9982efc6b309145ed80c4025f00b1e6af48b46dbd2fbb1a51f9844654f486c

See more details on using hashes here.

File details

Details for the file mosaik_api_v3-3.0.16-py3-none-any.whl.

File metadata

  • Download URL: mosaik_api_v3-3.0.16-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mosaik_api_v3-3.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 b66a5550b2a52b11d2a5805a8e3adbbf78ca3629fe6e2132accda9844c7ab64d
MD5 c1efeb919acd8d643e5c86924898b233
BLAKE2b-256 8e2b183f9f03e69b434af489982ca214877f44f6c9f5072342ef4357690ba4bb

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

3.0.16 This release

2 files

3.0.15

2 files

3.0.14

2 files

3.0.13

2 files

3.0.12

2 files

3.0.11

2 files

3.0.10

2 files

3.0.9

2 files

3.0.8

2 files

3.0.7

2 files

3.0.6

2 files

3.0.5

2 files

3.0.4

2 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