Import YAML configs into Arguments for Python
Project description
bibiflags is a python tool to import YAML configs into Arguments for Python .
It provides 2 ways to use it:
- Parse all Arguments from YAML: see example .
- Merge Arguments form YAML and existing argparse.ArgumentParser: see example .
Getting Started
Requirements and Installation
- Python version >= 3.8
- libaries:
- "PyYAML>=6.0.1"
pip install bibiflags
Install from source via:
pip install git+https://github.com/bibiparrot/bibiflags.git
Or clone the repository and install with the following commands:
git clone git@github.com:bibiparrot/bibiflags.git
cd bibiflags
pip install -e .
Usage
YAML file
flags:
- dest: filename
help: positional args
type: str
required: true
- default: string-type-arguments
dest: str_arg
help: string type args
option_strings:
- --str_arg
- -sa
type: str
- const: true
default: false
dest: bool_arg
help: bool type args
nargs: 0
option_strings:
- --bool_arg
- -ba
type: bool
- default: 8
dest: int_arg
help: int type args
option_strings:
- --int_arg
- -ia
type: int
- default: 0.1
dest: float_arg
help: float type args
option_strings:
- --float_arg
- -fa
type: float
- default:
- 1
- 2
- 3
- 4
dest: list_arg
help: list type args
nargs: +
option_strings:
- --list_arg
- -la
type: int
Parse all Arguments from YAML
from pathlib import Path
from bibiflags import BibiFlags
if __name__ == '__main__':
flags = BibiFlags(root=str(Path(__file__).parent))
print(flags.parameters)
Merge Arguments form YAML and existing argparse.ArgumentParser
from pathlib import Path
from bibiflags import BibiFlags
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("echo", action='store_true')
flags = BibiFlags(argparser=parser,
root=str(Path(__file__).parent),
app_name='main')
print(flags.parameters)
Changelog
Version 0.1.5 2024-4-14
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
bibiflags-0.1.5.tar.gz
(45.8 kB
view details)
Built Distribution
File details
Details for the file bibiflags-0.1.5.tar.gz
.
File metadata
- Download URL: bibiflags-0.1.5.tar.gz
- Upload date:
- Size: 45.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.13.3 CPython/3.8.16 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7099e0b117542fd82f04aea29d89a8dfa1f18b35200ab9d2ed3729e7521581bb |
|
MD5 | c7e8da4b50cfdbbe3ca024fa9cf76f36 |
|
BLAKE2b-256 | 66b42a1c8c9c05544d4d272d0de25ace6affecbfb42039e52a800fd319296c03 |
File details
Details for the file bibiflags-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: bibiflags-0.1.5-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.13.3 CPython/3.8.16 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3baae7599be91b9b833af71d51df852b1e84ec4e255399124c52332c6a9d83c8 |
|
MD5 | e0f9eb8654e9707d460bdf76fbc903c5 |
|
BLAKE2b-256 | c2c02ebfa2f39923dcdf8c626416c862cb482f8935784627bd7f7ebc975a4844 |