Skip to main content

Load and gen configuration for argparse

Project description

Save/Load your options to/into config

>>> from arconfig import GenConfigAction, LoadConfigAction
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument("--config", action=LoadConfigAction) # add it before another options
>>> parser.add_argument("--gen-config", action=GenConfigAction)
>>> parser.add_argument('-s', action='store', dest='simple_value', help='Store a simple value')
>>> parser.add_argument('-c', action='store_const', dest='constant_value',
... const='value-to-store', help='Store a constant value')
>>> parser.add_argument('-t', action='store_true', default=False,
... dest='boolean_switch', help='Set a switch to true')
>>> parser.add_argument('-f', action='store_false', default=False,
... dest='boolean_switch', help='Set a switch to false')

Generate simple config

$ python --gen-config
 "simple_value": null,
 "constant_value": null,
 "config": null,
 "boolean_switch": false

And load it

$ python --gen-config > /tmp/test.json
$ python --config=/tmp/test.json
 "simple_value": null,
 "constant_value": null,
 "config": null,
 "gen_config": false,
 "boolean_switch": false

All another arguments overwrite the config values (but counter are added).

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for arconfig, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size arconfig-0.1.3.tar.gz (2.9 kB) File type Source Python version None Upload date Hashes View
Filename, size arconfig-0.1.3-py3-none-any.whl (3.1 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page