Skip to content

Configuration Setup

jefmud edited this page Oct 8, 2022 · 7 revisions

Configuration

Minimus includes a special configuration object as part of the overarching Minimus object. It is config.

The app object can also load the configuration from a file.

Basic usage example

from minimus import Minimus

app = Minimus(__name__)

app.config.myname = 'Jack'

@app.route('/')
def index(env):
    return "Hello " + app.config.name

app.run()

That piece of code will greet Jack every time he hits the URL.

Configuration from file

Minimus also allows itself to accept a configuration file. The configuration file is a VERY basic text file that allows line-by-line assignment of configuration variables. For example, in we had app.py and greenhouse.cfg in the same directory, we could load the app.config with the strings seen below. Note that each of the temperatures are loaded as strings as well as the boolean. More complex configuration is left to the programmer.

In a later edition of the product, I will add the ability to have comments in the file as well as support for int, float, and boolean types. For now you're going to have to deal with this limitation.

Configuration from file example

greenhouse.cfg

name = "Greenhouse datalogger"
bay1_min_temp = 20
bay1_max_temp = 30
low_warning_temp = 19
high_warning_temp = 31
bay1_thermal_window = True

app.py

from minimus import Minimus

app = Minimus(__name__)

app.config_from_file('greenhouse.cfg')

@app.route('/')
def index(env):
    return f"""<pre>
	Hello from {app.config.name}
	Minimum temperature setting {app.config.bay1_min_temp} degrees C
	Warning issued at {app.config.low_warning_temp} degrees C
	</pre>
"""

app.run()

Limitation

The minimus app.config_from_file(<filename>) can only load one line strings. Conversion to other types or more complex configuration is left to the programmer.

Clone this wiki locally