comboparse
Drop-in replacement for argparse with support for environment variables.
How does it work
If environment variables are present that fit a certain schema they are internally appended as if you had added them as CLI arguments.
Usage
As a drop in replacement just use comboparser instead of argparse:
import comboparse
# notice the different classname its not argparse.ArgumentParser
parser = comboparse.ComboParser(
prog='ProgramName',
description='What the program does',
epilog='Text at the bottom of help')
parser.add_argument('filename')
parser.add_argument('-c', '--count')
parser.add_argument('-v', '--verbose',
action='store_true')
args = parser.parse_args()
If the environment variables FILENAME, COUNT or VERBOSE (for flags set them with 1, true or y) these values will be set accordingly
Prefix environment variables
Obviously for the sake of sanity we might want to prefix our environment variables, simply add the following parameter to the constructor:
import comboparse
# notice the different classname its not argparse.ArgumentParser
parser = comboparse.ComboParser(
# ...
env_prefix="combo", # please note that this will be upper cased
)
# ...
and now the env vars from before would be COMBO_FILENAME, COMBO_COUNT, COMBO_VERBOSE
Limitations
Environment variable names
The names can't be adjusted beyond setting the prefix and determined by the actions "dest" value. Aka whatever argparse would determine your "args.NAME" to be like.
Mixing CLI arguments and environment variables
While this should work as this tool simply adds its own CLI arguments to argparser, if you do something like
$ COUNT=10 my-tool --count 5 --verbose
The verbose flag will work as expected, but which count is taken isn't guaranteed by thiis library. (aka while now maybe the environment variable has precedence, in the future this might randomly change so don't rely on this!)
Action Type: count
Count actions are usually provided like this:
$ my-cli-tool -vvv
Namespace(verbose=3)
but as an env variable you have to provide the number as is
$ VERBOSE=3 my-cli-tool
Namespace(verbose=3)
Action Type: append_const
This works a bit like a normal store_true/store_false you have to use 1, true etc.
License
MIT
Metadata
Release files for comboparse 1.0.1
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 |
|---|---|---|---|---|
| comboparse-1.0.1.tar.gz | 8.3 kB | Without provenance | Details for comboparse-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| comboparse-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for comboparse-1.0.1-py3-none-any.whl |
Total release size: 13.0 kB
Release files / comboparse-1.0.1.tar.gz
| Download URL | comboparse-1.0.1.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ae306f807309a695ac3eb613e865dbf0e5f52474ee90d389a9192b575f467ca
|
|
BLAKE2b-256 checksum How to use checksums |
cf487a53b4333d36081b4a84f2ff86b36f57795f12dacfd8fe155453efd48a63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.1 CPython/3.11.3
|
Release files / comboparse-1.0.1-py3-none-any.whl
| Download URL | comboparse-1.0.1-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1c32b3d99ac8509d6dbe7a7b4b45f15859eb2357d868a59c631dfd478bb0c97c
|
|
BLAKE2b-256 checksum How to use checksums |
1d44c9a5dcd1717af2923fe1637b6bef70d8f1d1d0e062a7e0ec7b85f39abbe9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.1 CPython/3.11.3
|
Security for comboparse 1.0.1
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.