🧪 We're running a cheminformatics notebook competition!

Enter by October 4
58 / 103
EnvConfig

EnvConfig

by marimo team

Configure environment variables interactively.

About this notebook

This notebook shows the EnvConfig widget from the wigglystuff library. It uses marimo, the os module, and wigglystuff. The widget helps you load or set environment variables from inside a notebook. This is useful for tutorials that need API keys. The example defines three keys named VALIDATED_KEY, MY_API_KEY, and SIMPLE_KEY. Each key can take a validator function or None for a simple existence check.

The reader wraps EnvConfig in mo.ui.anywidget to render it. The widget tries to load each environment variable automatically. The reader can also type a value manually in the widget. A validator callback runs on each key. In this example, the check_key function raises an error when a key is shorter than five characters. The widget shows whether each key passes its check.

The reader can read a single value with an index, such as config_validated["MY_API_KEY"]. The all_valid property reports whether every input passes its check. You can use this property to stop other cells from running. The require_valid() method raises an error when any input is invalid.

Related notebooks