Configuration file parsing with argparse.
Project description
cargparse :blue_car:
A lightweight library to parse configuration files using argparse
.
- Robust type validation with
argparse
- Supports nested arguments with recursive calls to
argparse
- No syntax to learn, just use
argparse
!! :rocket:
Currently supports yaml
/yml
and json
files. ini
, toml
,
and others are under development.
Contributions welcome! :handshake:
Installation
pip install cargparse
Usage
Given config.yaml
...
text: hello world
decimal: 0.5
boolean: False
...your script might look like this...
import argparse
import cargparse
parser = argparse.ArgumentParser()
parser.add_argument('--text', type=str)
parser.add_argument('--decimal', type=float)
parser.add_argument('--boolean', type=lambda x: eval(x))
args = cargparse.YAML(parser=parser, filename='config.yaml')
...which returns a Namespace
object, just like ArgumentParser.parse_args()
!
>> args
Namespace(text='hello world', decimal=0.5, boolean=False)
>> args.text
'hello world'
>> type(args.decimal)
<class 'float'>
:boom: Nested dictionaries are Namespace
objects, too!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cargparse-0.0.4.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for cargparse-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b10d6f049552bf88ca574d0f02ac668e36895d6225b6b7adf354a5164bb3fa6b |
|
MD5 | 0f12b2f093dd2f762cf724cc4808c5f9 |
|
BLAKE2b-256 | 443280c1135b24b4ef8daebb06db27b018ee49a6b88ea3e9362c69be2980df1a |