A Typer config file get/set boilerplate¶
Using the boilerplate¶
Aliases and subcommands¶
We recommand the following aliases, which are readily available out of the box.
config
cfg
c
This way, if your app is named super-app
And is defined in super_app.py
roughly as follows:
You just have to add the following below:
You can rename them however you like by using
Using it on the command line¶
With the same configuration as above, your new app can now run the commands:
You can obviously use super-app config get
and others, or any name you attribute to it.
Using it within python modules¶
The CLI key-values are stored in a tinydb instance that is available by just importing the table named globals
:
Insert / Upsert¶
To insert a new value, the easiest is to use the upsert_param
.
This function is used to upsert a parameter (param
) and its corresponding value (value
) to the global database.
The function takes in 3 parameters: param
, value
, and obfuscate
.
- The
param
parameter is a string that contains the parameter name. - The
value
parameter can take in any type of value, and it contains the value to be upserted to the database. - The
obfuscate
parameter is a boolean value that determines if the parameter and its corresponding value will be obfuscated before being stored in the database.
The function uses the usual Query()
and db.search(..)
from tinydb.
The function upserts the param
and value
to the database, and also stores the timestamp
, machine
, and a boolean to indicate wether parameters are obfuscated.
Get Keys / Values¶
There are two pre-made functions: getKey
and getValue
. The key difference is as follows:
getKey
returns all the values associated with keykey
getValue
arbitrarily returns the first encountered value.
The underlying database¶
You can create any table using the database object db
, please check out the tinydb docs !
To get the key just use where
:
To insert new values or update existing, use the upsert
function:
Commands¶
Go check out the commands page 🚀