Skip to main content

Simplifies the process of parsing command-line arguments and configurations from YAML files

Project description

Installation

pip install yaml-arg-configer

YAML Argument Parser

Overview

The YamlArgParser class simplifies the process of parsing command-line arguments and configurations from YAML files, combining default values with those specified via the command line or additional YAML files.

Features

  • Default Configuration: Load default settings from a YAML file.
  • Command-Line Override: Override default settings using command-line arguments.
  • Multiple Configurations: Support for multiple YAML configuration files.
  • Help Documentation: Generate help documentation for each configuration option.

Default Configuration YAML File

Create a default configuration file (e.g., defaults.yaml) with settings:

arg1:
  default: ~ # Set arg1 default value to None
  help: "Help documentation for arg1"
arg2:
  default: ~ # Set arg2 default value to None
  help: "Help documentation for arg2"

User Configuration YAML Files

Create user configuration files (e.g., config1.yaml):

arg1: value1 # Set arg1 value to value1

And additional configurations (e.g., config2.yaml):

arg2: value2 # Set arg2 value to value2

Parse Command-Line Arguments

Use the parse_args function to parse command-line arguments:

from yaml_arg_configer import YamlArgParser

yaml_parser = YamlArgParser()
cmd_args = yaml_parser.parse_cmd_args()
# return config with dict format by default
args = yaml_parser.parse_args(cmd_args)

print(args)
# config with argparse.Namespace format
print(yaml_parser.get_args())

Command-Line Usage

Run your script with configuration options:

python my_script.py -dc defaults.yaml -d configs -c config1 config2
  • -d, --cfg_dir: Directory containing configuration files.
  • -c, --cfg: Names of configuration files to use (without .yaml extension).
  • -dc, --default_yaml: Path to the default yaml file, it's optional when a path is passed in YamlArgParser()
  • -ctx, --ctx_yaml: Path to the context yaml file, it's optional
  • --strict: Constraints user configuration defined in the default_yaml file
  • --doc: Get help documentation for a specific argument.
  • --docs: Print help documentation for all arguments.

Accessing Configurations

Retrieve parsed configurations using:

print(yaml_parser.get_args_dict())
print(yaml_parser.get_args())
print(yaml_parser['arg1'])

Saving Configurations

Save current configurations to a YAML file:

yaml_parser.save_config('output_config.yaml')

Contributing

Contributions are welcome! Please fork the repository, make your changes, and submit a pull request. Ensure that any new features or bug fixes include appropriate tests.

License

This project is licensed under the MIT License.

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

yaml_arg_configer-0.1.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yaml_arg_configer-0.1.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file yaml_arg_configer-0.1.2.tar.gz.

File metadata

  • Download URL: yaml_arg_configer-0.1.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for yaml_arg_configer-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1b40cf2e4cd1f5d7a444b1c8ce0988e56d1bfa2ae06d2e12d8d1d7b9e4d570b5
MD5 ff89bf445d30f4d0e4daafaf33d84a52
BLAKE2b-256 a299fecd9435b05a307dd7de149499775758c7c9f5ccc399a539c56eb9fe6ed5

See more details on using hashes here.

File details

Details for the file yaml_arg_configer-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for yaml_arg_configer-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b7bb42fac7fcec29c73641617f2ecf70fe257a111013c656ff0e4297c531ce31
MD5 ccb1eaf9b04b71507a8c5c12d9911c55
BLAKE2b-256 d139ecaf54ad64f2a00be76eef24f01d7ca0e2a1eab555301e26da9aab7852e0

See more details on using hashes here.

Supported by

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