Skip to content

Extending Chaos Toolkit with Python

Create your new Chaos Toolkit extension project

All Chaos Toolkit extensions follow the same structure and you can benefit from a project generator such as cookiecutter. This will drive you through a set of basic questions for metadata and will create a local project you can then start put your code into.

Let’s use the community-driven template project:

$ pip install - U cookiecutter
$ cookiecutter

Where to put your code

There are two extension points for a Chaos Toolkit Python extension, and they are captured in two files: and

It is conventional to use the module as the place where you expose the actions that you would like to conduct as part of your Chaos Toolkit experimental method against the environment you want to inject failure into.

It’s also conventional to use the module as the place where you can integrate with your system’s existing observability so that those values can be used either for an experiment’s Steady State Hypothesis, or as simple additional data-gathering probes that can be declared throughout an experiment’s method.

Running Discover on a New Extension

Chaos Toolkit extensions often implement functionality that assists in discovering what a system, and the extension against that system, supports. This is executed using the chaos discover command.

When writing your own implementation of discovery you will often want to test the new functionality locally. To do this you should first execute from your extension workspace:

$ python develop

Then you can exercise your discovery functionality using the --no-install flag on the chaos discover command, for example:

chaos discover --no-install ext-name

Log From Your Extension

You can write to the Chaos Toolkit log by using the logzero package.

from logzero import logger"Hello!")

Make sure to add logzero as an entry of the requirements.txt file of your extension.