Module to assist in defining application options and collecting user input for them from command line and environment variables.
Project description
anparams
A python3 module to assist in defining application options and collecting user input for them from command line and environment variables.
Install
pip3 install anoptions
Usage
Follow the example. If short_name is omitted, the first letter of the "long" name parameter is used. Duplicate short or long names are not allowed.
Func is a required parameter. Give a function that converts the inputted value to the proper data type. If no conversion is desired, you can use Parameter.dummy
.
For flags where existence of a variable will always mark True use Parameter.flag
.
For flags where a more logical input parsing (for example silent='false' to be interpreted as False) is desired use Parameter.bool
(or just bool
).
Example
Code (main.py):
from anparams import Parameter, Options
def main(argv):
parameters = [
Parameter("host", str, "mqtt_host"),
Parameter("port", int, "mqtt_port"),
Parameter("topic", str, "mqtt_topic"),
Parameter("dir", str, "directory"),
Parameter("delta", int, "delta", short_name='D'),
Parameter("silent", bool, "silent")
]
opt = Options(parameters, argv, 'appname')
d = opt.eval()
print(d)
if __name__ == "__main__":
main(sys.argv[1:])
Run:
$ APPNAME_PORT=1232 APPNAME_SILENT=1 python3 main.py -d /tmp --host 10.1.2.3 -D 60
{'mqtt_port': 1232, 'silent': True, 'filename_dir': '/tmp', 'mqtt_host': '10.1.2.3', 'delta': 60}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for anoptions-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d002c785d46375d19c71c8b53b0f57786a2ec356e356397224743a9c3b3829a |
|
MD5 | 4c10a2fb8f2f75003a219413d7af9f24 |
|
BLAKE2b-256 | d2a83fe273aec98a870de47692d18675f0e8d57777db9f967bd57e0cd4711e32 |