Skip to main content

confused-argparse

Build Status Coverage Python Version wemake-python-styleguide

Note: VERY Beta, please wait for relase 1.0, since it is not even complete yet

"My standard" goto package for all my scripts/apps. Get argparse cli and configuration management in ONE LINE per parameter ;-)

With minimal boilerplate to handle:

  • System, default and script level configuration management files with confuse using YAML
  • OS enviroment does overwite settings from YAML
  • Automagic argparse CLI creation and handling. Will overwrite all settings from YAML and os enviroment
  • Setting the logging level

And:

  • Creating the user default and script level YAML files at first run
  • Optional: Saving state at exit
  • and so much more ...

See:

Install:

  • bash Shell:
$ python3 -m venv /path/to/new/virtual/environment
$ cd /path/to/new/virtual/environment
$ source ./bin/activate
$ pip install confused-argparse

First Excample

  • PROGNAME.py:
import confused-argparse
ca=confused-argparse.set_var()
ca('input_file', str, 'Input file: Read from a local file')

Behind the scenes:

  • If input_file was set in any of the YAML files, it will already have a value (Actually views of values, see confuse)
  • If input_file was set in the os enviroment, input_file will be set accrodingly, overriting the YAML setting
  • If --input_file was set via the command line interface with python3 PROGNAME.py --input_file my_file.txt, overriting the YAML and os enviroment setting to my_file.txt

In the bash shell:

$ python3 PROGNAME.py -h

usage: PROGNAME.py [-h] [--input_file INPUT_FILE]

optional arguments:
  -h, --help                  show this help message and exit
  --input_file INPUT_FILE     Input file: Read from a local file

Next level:

  • PROGNAME.py:
import confused-argparse
ca = confused-argparse.set_var(standard=True, description='My App: Solves a problem')
ca('input_file', str, 'Input file: Read from a local file', group='I/O')

Behind the scenes:

  • standard=True:
    • There are a number of standard argparse options already set, like --verbose, --debug, --cron
    • Scans and read the values defined in the os enviroment, case independant, so also the enviroment variable VERBOSE
    • For excample: --verbose will set the logging level to INFO
  • description='My App: Solves a problem'
    • argparse will print this
  • group='I/O':
    • argparse will group options with this optional parameter
$ python3 PROGNAME.py -h

usage: PROGNAME.py [-h] [--input_file INPUT_FILE] [--list_defaults] [--debug] [--verbose] [--cron]

My App: Solves a problem

optional arguments:
  -h, --help                  show this help message and exit

I/O:
  --input_file INPUT_FILE     Input file: Read from a local file [str]=''

Debug options:
Note: Will override 
  --list_defaults             List: List all Vars in dict with there Defaults [bool]=False
  --debug                     Debug: Logging DEBUG Messages (if not --cron, overrides --verbose) [bool]=False
  --verbose                   Verbose: Logging INFO Messages (if not --cron) [bool]=False
  --cron                      Called from Cronjob [bool]=False

Want more?

See Documentation. (Soon)

Pull Requests?

  • Will be welcomed, when we reached the first beta
  • Note: The confused-argparse github repository is still private/closed

DEV

License

MIT

(c) 2020 Nikolai von Krusenstiern

Credits

This project was generated with wemake-python-package. Current template version is: 69435b231f7f398474073ac6dd14868dd3edf2c1. See what is updated since then.

Metadata

Release files for confused-argparse 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for confused-argparse 0.2.2
File Size Uploaded
confused-argparse-0.2.2.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for confused-argparse 0.2.2
File Interpreter ABI Platform
confused_argparse-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / confused-argparse-0.2.2.tar.gz

Download URL confused-argparse-0.2.2.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
fc4776b4653ed5b9e4d16d85434a5156f69f3df1bb74825c452825da250ba76c
BLAKE2b-256 checksum
How to use checksums
5ec21086814916a50f761ea17b8f02ea8e0c4315358d8da3896df13a58879358
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.8.5 Darwin/18.6.0

Release files / confused_argparse-0.2.2-py3-none-any.whl

Download URL confused_argparse-0.2.2-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7651aee55f7a39b35158f704ca96a7e96196ec89feecc8498dfa5c55960756a5
BLAKE2b-256 checksum
How to use checksums
0f08bf249334263194df04a523e3dc1554eed89c4574249ea22d9ba58b615039
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.8.5 Darwin/18.6.0

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page