A domain specific language to describe neuron models in NEST
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


astropy Build Status

PyNestML - The NEST Modelling Language @Python

NestML is a domain specific language that supports the specification of neuron models in a precise and concise syntax, based on the syntax of Python. Model equations can either be given as a simple string of mathematical notation or as an algorithm written in the built-in procedural language. The equations are analyzed by NESTML to compute an exact solution if possible or use an appropriate numeric solver otherwise.

Directory structure

models - Example neuron models in NestML format.

pynestml - The source code of PyNestML.

tests - A collection of tests for testing of the toolchain's behavior.

doc - The documentation of the modeling language NestML as well as processing toolchain PyNestML.

extras - Miscellaneous development tools, editor syntax highlighting rules, etc.

Installing NESTML

In order to execute the language tool-chain, Python in version 2 or 3 is required. A setup file is provided and can be installed by

python2 setup.py install --user

For Python in version 3, respectively:

python3 setup.py install --user

Correct installation can be tested by

python2 setup.py test
\# respectively python3 setup.py test 

In order to ensure correct installation and resolving of dependencies, Python's package manager pip, the distribution tool setuptools as well as the python-dev package are required and should be installed in advance. The setup file additionally installs the following components:

In the case that no 'enum' package is found, additionally, enum34 has to be updated by

pip install --upgrade pip enum34

All requirements are stored in the requirements.txt and can be installed in one step by pip

pip install -r requirements.txt

Running NESTML

After the installation, the toolchain can be executed by the following command.

python PyNestML.py ARGUMENTS

where arguments are:

Command Description
-h or --help Print help message.
--input_path Path to the source file or directory containing the model.
--target_path (Optional) Path to target directory where models will be generated to. Default is target.
--target (Optional) The name of the target platform to generate code for. Default is NEST.
--logging_level (Optional) Sets the logging level, i.e., which level of messages should be printed. Default is ERROR, available are [INFO, WARNING, ERROR, NO]
--module_name (Optional) Sets the name of the module which shall be generated. Default is the name of the directory containing the models. The name has to end in "module". Default is nestmlmodule.
--store_log (Optional) Stores a log.txt containing all messages in JSON notation. Default is OFF.
--dev (Optional) Executes the toolchain in the development mode where errors in models are ignored. Default is OFF.

Generated artifacts are copied to the selected target directory (default is target). In order to install the models into NEST, the following commands have to be executed from within the target directory:

cmake -Dwith-nest=<nest_install_dir>/bin/nest-config .
make all
make install

where <nest_install_dir> is the installation directory of NEST (e.g. /home/nest/work/nest-install). Subsequently, the module can either be linked into NEST (see Writing an extension module), or loaded dynamically using the Install API function. For example, to dynamically load a module with module_name = nestmlmodule in PyNEST:


PyNestML is also available as a component and can therefore be used from within other Python tools and scripts. After PyNestML has been installed, the following modules have to be imported:

from pynestml.frontend.pynestml_frontend import to_nest, install_nest

Subsequently, it is possible to call PyNestML from other Python tools and scripts via:

to_nest(input_path, target_path, logging_level, module_name, store_log, dev)    

This operation expects the same set of arguments as in the case of command line invocation. The following default values are used, corresponding to the command line defaults. Possible values for logging_level are the same as before ('INFO', 'WARNING', 'ERROR', 'NO'). Note that only the path argument is mandatory:

Argument Type Default
input_path string no default
target_path string None
logging_level string 'ERROR'
module_name string nestmlmodule
store_log boolean False
dev boolean False

If no errors occur, the output will be generated into the specified target directory. In order to avoid an execution of all required module-installation routines by hand, PyNestML features a function for an installation of NEST models directly into NEST:

install_nest(models_path, nest_path)

Here, models_path should be set to the target directory of to_nest(), and nest_path points to the directory where NEST is installed (e.g., /home/nest/work/nest-install).

A typical script, therefore, could look like the following. For this example, we assume that the name of the generated module is nestmlmodule.

from pynestml.frontend.pynestml_frontend import to_nest, install_nest

to_nest(input_path="/home/nest/work/pynestml/models", target_path="/home/nest/work/pynestml/target", dev=True)

install_nest("/home/nest/work/pynestml/target", "/home/nest/work/nest-install")


Further reading

For an in-depth introduction to the underlying modeling language NestML, please refer to the NestML language documentation.

For those interested in the implementation of PyNestML or the general structure of a DSL-processing toolchain, please refer to the PyNestML documentation.


  • Inga Blundell, Dimitri Plotnikov, Jochen Martin Eppler and Abigail Morrison (2018) Automatically selecting a suitable integration scheme for systems of differential equations in neuron models. Front. Neuroinform. doi:10.3389/fninf.2018.00050. Preprint available on Zenodo.

  • Konstantin Perun, Bernhard Rumpe, Dimitri Plotnikov, Guido Trensch, Jochen Martin Eppler, Inga Blundell and Abigail Morrison (2018). Reengineering NestML with Python and MontiCore (Version 2.4). Zenodo. doi:10.5281/zenodo.1319653.

  • Dimitri Plotnikov, Bernhard Rumpe, Inga Blundell, Tammo Ippen, Jochen Martin Eppler and Abigail Morrison (2016). NESTML: a modeling language for spiking neurons. In Modellierung 2016, March 2-4 2016, Karlsruhe, Germany. 93–108. doi:10.5281/zenodo.1412345.