Package for combining config and command-line args
Project description
Project description
config-args is a Python library for reading configuration from config files and command-line args.
Installation
pip install argumento
Usage
You can define configuration parameters both in config files and in command-line arguments.
Command-line args have higher priority: param values from command line overwrite values from config files.
Supported config file formats are:
- yaml (.yaml, .yml)
- toml (.toml)
- json (.json)
Basic example
import argumento
cfg_filename = 'my_config.yaml'
args = argumento.create_parser(cfg_filename).parse()
my_config.yaml:
login: "my_login"
max_retries: 5
ports: [ 8000, 8001, 8002 ]
ratio: 0.5
nice_bool_false: False
nice_bool_true: True
command line:
<command> --login my_login --max_retries 5 --ports: [ 8000, 8001, 8002 ] \
--ratio 0.5 --nice_bool_false False --nice_bool_true True
Bool arguments
Note that bool args should be set in command line via 'nice' but non-canonical way.
Supported usage:
--nice_bool_false False --nice_bool_true True
or
--nice_bool_false false --nice_bool_true true
Not supported usage:
--feature
/ --no-feature
style.
Required params not defined in config
If a parameter is required but is not set in config file, ?:
followed by type name is used instead of a value:
login: "?:str"
max_retries: "?:int"
ratio: "?:float"
ports: "?:list[int]"
fractions: "?:list[float]"
Supported data types are:
- str
- int
- float
- list[int]
- list[float]
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 argumento-1.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 810f0a31e1789d605e0e92ef4c37a50f717a3be8b7a1d89d3178155a803da880 |
|
MD5 | 28be5a30f27721153df438f9d764986c |
|
BLAKE2b-256 | e1d3831ebbe1b53b71a8f3253208a1d1061c03bd6ac313d4918265bbc8a4c2a6 |