Skip to main content

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:

python pypi version code style: black

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


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.7.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

cargparse-0.0.7-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page