Skip to main content

python for command line interface development

Project description

py4cli

  • Python for Command Line Interface development ( scalable argument parser ).
  • Argument Parser for developing Command Line Tools, that is scalable as per need.
  • Check out the example code in repo ( https://github.com/Palani-SN/py4cli ) for reference.

Minimal

  • Sample code as shown below can read arguments in specified type as per function signature. (refer use_minimal.py under EXAMPLES/)
from py4cli.minimal import arg_parser

# Multiple arguments example

class multi_args(arg_parser):

    # example parse_args template function with multiple arguments of different types
    def parse_args(self, 
            inp_int: int = 6,
            inp_float: float = 6.0,
            inp_str: str = "Six",
            inp_list: list = [6, 6.0, "Six"],
            inp_tuple: tuple = (6, 6.0, "Six"),
            inp_set: set = {"Six"},
            inp_dict: dict = {'int': 6, 'float': 6.0, 'str': "Six"},
            inp_bool: bool = False) -> dict:
        """
        Seven arguments of different data type can be passed
        any value of the respective data type can be passed for specific argument. for defaults refer above
        the function returns a json string containing all the arguments and its values.

        cmds :
            1. python <__file__> 10 10.0 Seven [10,10.0,'Seven'] (10,10.0,'Seven') {1,2,3,1.0,2.0,3.0} {'int':10,'float':10.0,'str':'Seven'} True
            2. python <__file__> -inp_int=10 -inp_float=10.0 -inp_str=Seven -inp_list=[10,10.0,'Seven'] -inp_tuple=(10,10.0,'Seven') -inp_set={1,2,3,1.0,2.0,3.0} -inp_dict={'int':10,'float':10.0,'str':'Seven'} -inp_bool=True
        """
        return {
                'inp_int': inp_int,
                'inp_float': inp_float,
                'inp_str': inp_str,
                'inp_list': inp_list,
                'inp_tuple': inp_tuple,
                'inp_set': inp_set,
                'inp_dict': inp_dict,
                'inp_bool': inp_bool
            }
    
if __name__ == '__main__':

    import sys
    import json

    print(sys.argv)
    obj = multi_args()
    print("")
    if obj.returned:
        out_dict = obj.returned.copy()
        out_dict['inp_set'] = list(out_dict['inp_set'])
        print(json.dumps(out_dict, indent=2, sort_keys=True), type(obj.returned))
  • To get help on how to use the script, execute python use_minimal.py -h or python minimal.py --help which will generate the doc content based on the comments in script as shown below.
output

(py4cli) D:\GitRepos\py4cli\EXAMPLES>python use_minimal.py --help
['use_minimal.py', '--help']

 | > def parse_args
 |
 |  Description :
 |
 |    example parse_args template function with multiple arguments of different types
 |
 |  Arguments :
 |
 |   -inp_int: int = 6
 |   -inp_float: float = 6.0
 |   -inp_str: str = 'Six'
 |   -inp_list: list = [6, 6.0, 'Six']
 |   -inp_tuple: tuple = (6, 6.0, 'Six')
 |   -inp_set: set = {'Six'}
 |   -inp_dict: dict = {'int': 6, 'float': 6.0, 'str': 'Six'}
 |   -inp_bool: bool = False
 |
 |  Usage :
 |
 |    Seven arguments of different data type can be passed
 |    any value of the respective data type can be passed for specific argument. for defaults refer above
 |    the function returns a json string containing all the arguments and its values.
 |
 |    cmds :
 |    1. python use_minimal.py 10 10.0 Seven [10,10.0,'Seven'] (10,10.0,'Seven') {1,2,3,1.0,2.0,3.0} {'int':10,'float':10.0,'str':'Seven'} True
 |    2. python use_minimal.py -inp_int=10 -inp_float=10.0 -inp_str=Seven -inp_list=[10,10.0,'Seven'] -inp_tuple=(10,10.0,'Seven') -inp_set={1,2,3,1.0,2.0,3.0} -inp_dict={'int':10,'float':10.0,'str':'Seven'} -inp_bool=True
 |
 | -> dict (Returnable)

  • The commands specified can be used to alter the values as command line arguments to the script.
output

(py4cli) D:\GitRepos\py4cli\EXAMPLES>python use_minimal.py -inp_int=10 -inp_float=10.0 -inp_str=Seven -inp_list=[10,10.0,'Seven'] -inp_tuple=(10,10.0,'Seven') -inp_set={1,2,3,1.0,2.0,3.0} -inp_dict={'int':10,'float':10.0,'str':'Seven'} -inp_bool=True
['use_minimal.py', '-inp_int=10', '-inp_float=10.0', '-inp_str=Seven', "-inp_list=[10,10.0,'Seven']", "-inp_tuple=(10,10.0,'Seven')", '-inp_set={1,2,3,1.0,2.0,3.0}', "-inp_dict={'int':10,'float':10.0,'str':'Seven'}", '-inp_bool=True']

{
  "inp_bool": true,
  "inp_dict": {
    "float": 10.0,
    "int": 10,
    "str": "Seven"
  },
  "inp_float": 10.0,
  "inp_int": 10,
  "inp_list": [
    10,
    10.0,
    "Seven"
  ],
  "inp_set": [
    1,
    2,
    3
  ],
  "inp_str": "Seven",
  "inp_tuple": [
    10,
    10.0,
    "Seven"
  ]
} <class 'dict'>

Moderate (in progress)

  • Vertically scalable version of minimal arg parser, aimed at use case like, hyper parameter tuning.

Maximal (in progress)

  • Horizontally scalable version of minimal arg parser, aimed at use case like, workflow development for testing & debug needs.

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

py4cli-0.0.4.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

py4cli-0.0.4-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file py4cli-0.0.4.tar.gz.

File metadata

  • Download URL: py4cli-0.0.4.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/6.7.0 pkginfo/1.10.0 requests/2.31.0 requests-toolbelt/1.0.0 tqdm/4.66.2 CPython/3.7.16

File hashes

Hashes for py4cli-0.0.4.tar.gz
Algorithm Hash digest
SHA256 6dbc0389f135c176db3161d9e79020147fa95267eb26362a40b1c6b49c8c7100
MD5 b740a84b7c9450ac4dbbfd1ce5960ddb
BLAKE2b-256 0f12edb3238034d442ec69b1c527ca5b13430c0ae9d8ac998e0d8b66d53e1123

See more details on using hashes here.

File details

Details for the file py4cli-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: py4cli-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/6.7.0 pkginfo/1.10.0 requests/2.31.0 requests-toolbelt/1.0.0 tqdm/4.66.2 CPython/3.7.16

File hashes

Hashes for py4cli-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 34dbb9e0d33f67633816ef65bd7101125b9862acd9c2c353c752d1c1b1cc5558
MD5 7e6d15c39bc7732a8fb93e20a63b8117
BLAKE2b-256 5c2a9d45544942a2cdb188089368a3757ebb0c91fee1890baeda59e51230f98f

See more details on using hashes here.

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