Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

argconfig

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

argconfig

Argparse enhanced with a config file to overwrite code-based defaults

  • 0.0.1
  • PyPI
  • Socket score

Maintainers
1

argconfig

argparse + yaml config system

This takes the same format as the argparse.ArgumentParser class; however it adds the feature of setting a default yaml file for base configuration to override the default set in the code. Usage has the following overwrite priority:

command line > config file > default set in code

This enables a flexible configuration based, commandline interface options at scale.

Requirements

  • Python 3.7+
  • pyyaml
  • argparse

Example

Config File

Use the example.yaml config file in the same directory as your example python code:

$ cat example.yaml
foo : test1
bar : 2.0

Example Code

The example python code setsup the variables foo and bar to equal 'testing' and 2.0 respectively. (Note the syntax is almost identical as argparse.ArgumentParser.)

import argconfig

parser = argconfig.ArgumentParser(description='argconfig example',config='./example.yaml')
parser.add_argument('-f','--foo', type=str, default='testing',
                    help='foo (default=testing, config=test)')
parser.add_argument('--bar',
                    help='bar (default=None, config = 2.0)')
args = parser.parse_args()

print('foo:',args.foo)
print('bar:',args.bar)

Example Command Line Usage

Run time of the example with foo and bar set by command line:

python example.py --foo test --bar 3.0

returns the following two print statements:

foo: test
bar: 3.0

While the values set in example.yaml is used when the values are not overriden by the command line:

python example.py

returns the following two print statements:

foo: test1
bar: 2.0

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc