Skip to main content

rdee-series toolkits: python-easyarg

Project description

rdee-python-easyarg

  • This package is primarily designed to automatically generate command-line interfaces for functions.
  • Inspired by typer and fire, they aim to achieve comprehensive functionality but requires the insertion of specific code snippets into the codebase.
  • This project intends to generate command-line interfaces for functions without intruding into the function code (using the decorator pattern) or even the entire script (using the pyfexe executable).
  • The trade-off is that all function parameters must have type annotations, and at least one must be of a primitive type (float, int, str, or bool).

Install

  • pip install rdee-easyarg

Examples

CLI-app mode

  • In this mode, we use a decorator to declare CLI interface
import easyarg

ea = easyarg.EasyArg()

# @ea.command()
# @ea.command(desc="manual description rather than docstring")
@ea.command(name="func1", alias="f", defaults={"y": 3}, choicess={"x": (1,2,3)})
def f1(x: int, y: int, flag1: bool, flag2: bool = False):
    """


    :param x: this info will be read as argument description in -h, --help
    :param y: {3,4,5} the leading {...} will be parsed into choices if not specified
    """
    print(x+y)


if __name__ == "__main__":
    ea.parse()
  • You can run the script directly, such as ./a.py f1 --x 1 --y 2, and get 3
  • -h/--help for app level and function level are both supported

CLI-executor mode

  • In this mode, we can execute a function in CLI without INSERTING any code
  • For instance, given the funcs.py
def add(x: int, y: int = 0) -> int:
    print(x + y)

def failfunc(x, y):
    pass

def mul(a: float, B: float, c: float = 1.0) -> float:
    print(a * B * c)
  • run pyfexe funcs.py -h to check valid functions to execute
  • then run pyfexe funcs.py add -h to check usage of target function
  • then run pyfexe funcs.py add -x 1 execute the function "add", with x=1, y=0

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

rdee_easyarg-25.2.26.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

rdee_easyarg-25.2.26-py2.py3-none-any.whl (11.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file rdee_easyarg-25.2.26.tar.gz.

File metadata

  • Download URL: rdee_easyarg-25.2.26.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for rdee_easyarg-25.2.26.tar.gz
Algorithm Hash digest
SHA256 62a8b0f30c601c501a692965d95b1b75698002b0d8900d17e144e6672d7902e3
MD5 d46c5a8ccee96c69c40e6ed991685284
BLAKE2b-256 d9d697f27d159392db59b7bf02ea65a1b6dd198092e1140a38b2a29dff30a1bd

See more details on using hashes here.

File details

Details for the file rdee_easyarg-25.2.26-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for rdee_easyarg-25.2.26-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 23b9504677775bab02a43a33b628e5b8aac057b2c7347648c4a06a8bf5ad9698
MD5 7564ea4117ca7d83fb7c1a38bd3724bc
BLAKE2b-256 72f53a98d9c9a1f0ac6e8204f54abbcd5185f6a7c7840c9fa2ad4f7ae3aa866d

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