# pyarg **Repository Path**: yhyu13/pyarg ## Basic Information - **Project Name**: pyarg - **Description**: Python argparser wrapper - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2023-11-27 - **Last Updated**: 2025-07-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # PyArg : No longer passing "args" around! ## Overview pyarg is a simple wrapper for argparser that only parse argument on the fly. Now you can declare cmd line argument as you go. No longer passing "args" via functions! Required Python>=3.7 ## Install ### Local install To be able to debug the code, you can install the package in editable mode. ``` pip install -e . ``` ### Wheel install To build a wheel, run the following command: ``` pip install build wheel rm -rf ./dist python -m build --wheel . pip install ./dist/*.whl ``` or simply run `./install_wheel.sh` ### Release on gitee PyCmake is available to install from gitee release https://gitee.com/yhyu13/pyarg.git ## Features Easy to use, just call pyarg() with the argument name and its properties as parameters. Supports all argparser's argument properties. Logs the parsed arguments and any unknown arguments for debugging purposes. ## Usage [./example/hello.py](./example/hello.py) work just like argparser parsing args ``` from PyArg import pyarg # python example/hello.py --name Alice --age 30 --flag if __name__ == '__main__': import logging logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) pyarg('--age', help='Your age', type=int, default=0) pyarg('--flag', help='A boolean flag', action='store_true') pyarg('--name', help='Your name', type=str, required=True) print(f"Hello, {pyarg.args.name}! You are {pyarg.args.age} years old.") if pyarg.args.flag: print("Flag is set.") ``` Output ``` python example/hello.py --age 30 --flag --name Alice DEBUG:pyarg[debug]: parsed --age, known args Namespace(age=30), unknown ['--flag', '--name', 'Alice'] DEBUG:pyarg[debug]: parsed --flag, known args Namespace(age=30, flag=True), unknown ['--name', 'Alice'] DEBUG:pyarg[debug]: parsed --name, known args Namespace(age=30, flag=True, name='Alice'), unknown [] Hello, Alice! You are 30 years old. Flag is set. ``` [./example/world.py](./example/world.py) **now the magic, you can declare arguments on the fly, no longer passing args across methods and modules!** ``` from PyArg import pyarg # python example/hello.py --name Alice --age 30 --flag if __name__ == '__main__': import logging logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) print(f"Hello, {pyarg('--name', help='Your name', type=str, required=True)}! You are {pyarg('--age', help='Your age', type=int, default=0)} years old.") if pyarg('--flag', help='A boolean flag', action='store_true'): print("Flag is set.") ``` Output ``` python example/world.py --age 30 --flag --name Alice DEBUG:pyarg[debug]: parsed --name, known args Namespace(name='Alice'), unknown ['--age', '30', '--flag'] DEBUG:pyarg[debug]: parsed --age, known args Namespace(name='Alice', age=30), unknown ['--flag'] Hello, Alice! You are 30 years old. DEBUG:pyarg[debug]: parsed --flag, known args Namespace(name='Alice', age=30, flag=True), unknown [] Flag is set. ```