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.
configcfgc
This way, if your app is named super-app
And is defined in super_app.py roughly as follows:
import typer
# ... some imports
app = typer.Typer(
name='super-app',
# ... other args
)
You just have to add the following below:
from typer_tinydb import cfg, config # those are typer apps
app.add_typer(cfg) # the cfg app
app.add_typer(config) # the config app
You can rename them however you like by using
app.add_typer(cfg, name='my-super-config')
Using it on the command line
With the same configuration as above, your new app can now run the commands:
super-app cfg list # list config key:value pairs
super-app cfg get some-key # get the values linked to the key 'some-key'
super-app cfg set some-key '20-hS407zuqYKQ8tPP2r5' # store some hash or token into your settings file
super-app cfg set -k user23 'supersecretpassword' # it's going to get obfuscated so looking at the JSON doesn't help
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:
from typer_tinydb import db, globals, where
Insert / Upsert
To insert a new value, the easiest is to use the upsert_param.
def upsert_param(param:str, value:Any, obfuscate: bool = False):
...
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
paramparameter is a string that contains the parameter name. - The
valueparameter can take in any type of value, and it contains the value to be upserted to the database. - The
obfuscateparameter 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:
getKeyreturns all the values associated with keykeygetValuearbitrarily 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 :
returns = globals.search(where('param') == param)
To insert new values or update existing, use the upsert function:
Param = Query()
globals.upsert({
"param": param,
"value": value,
"timestamp": datetime.now().strftime("%d/%m/%Y %H:%M:%S"),
"machine": socket.gethostname(),
},
Param.param == param
)
Commands
Go check out the commands page 🚀
Metadata
Release files for typer-tinydb 0.1.4.post0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| typer_tinydb-0.1.4.post0.tar.gz | 12.6 kB | Without provenance | Details for typer_tinydb-0.1.4.post0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| typer_tinydb-0.1.4.post0-py3-none-any.whl | Python 3 | none | any | Details for typer_tinydb-0.1.4.post0-py3-none-any.whl |
Total release size: 26.0 kB
Release files / typer_tinydb-0.1.4.post0.tar.gz
| Download URL | typer_tinydb-0.1.4.post0.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4c9d1a3a826b514b445bd30620308f105f9307f31bf496c9f7a0341c0aa93fc4
|
|
BLAKE2b-256 checksum How to use checksums |
5cfe3fe34e570a81e27fcacadd0257ddcba885be20f9c23f9ee3e19014f78bad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.11.4 Linux/6.3.12-204.fsync.fc38.x86_64
|
Release files / typer_tinydb-0.1.4.post0-py3-none-any.whl
| Download URL | typer_tinydb-0.1.4.post0-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
837e6cbc6e4fb83ba2ab86c833bc6ecd7f370be2d66922f0cda4cc920786eb35
|
|
BLAKE2b-256 checksum How to use checksums |
7242cd504015b719674adba47a0d41d877d0cc76486954f7a316e4e14c00d85c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.11.4 Linux/6.3.12-204.fsync.fc38.x86_64
|
Security for typer-tinydb 0.1.4.post0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.