Skip to main content

Ask4args

Ask for function args by Terminal UI / GUI, ensuring the type annotation. Inspired by python-fire, and it maybe need a human-friendly interactive UI.

Install

pip install ask4args -U

Simple Usage

python3 -m ask4args module:function

Terminal UI

demo.gif

GUI

demo2.png

More Usage Examples

from ask4args.core import Ask4Args, Ask4ArgsGUI, Ask4ArgsWeb
from typing import List, Dict


def test_normal_function(a: int, b: int = 2, **args_dict: Dict[str, int]):
    # first a value=1, args_dict['c']=3, others use default.
    # press 1, enter, enter, enter, c, enter, 3, enter, enter
    assert a == 1
    assert b == 2
    assert args_dict['c'] == 3
    return ('success', vars())


def test_keyword_only_function(a: float,
                               b: int = 2,
                               *,
                               c: bool = False,
                               d: str = 'string',
                               e: int = None,
                               f: List[int] = None,
                               **args_dict: Dict[str, int]):
    """Read the doc, and test kw-only args.

    :param a: one float num
    :type a: float
    :param b: one int num, defaults to 4
    :type b: int, optional
    :param c: boolen arg, defaults to False
    :type c: bool, optional
    :param d: string arg, defaults to 'string'
    :type d: str, optional
    :return: return the args_dict
    :rtype: Dict[str, list]
    """
    assert a == 1.1
    assert b == 2
    assert c is False
    assert d == 'string'
    assert e == 1
    assert f == [1, 2, 3]
    assert args_dict['h'] == 3
    return ('success', vars())


class TestClass(object):

    def test_method(self, a: str, b: int = 1):
        assert a == ''
        assert b == 1
        return ('success', vars())

    @classmethod
    def test_class_method(cls, a: str, b: int = 1):
        assert a == ''
        assert b == 1
        return ('success', vars())


def test_defaults(a: int):
    assert a == 1
    return ('success', vars())


if __name__ == "__main__":
    # cls = Ask4ArgsWeb
    cls = Ask4Args
    # cls = Ask4ArgsGUI
    # =====================
    # =====================
    # ('success', {'a': 1, 'b': 2, 'args_dict': {'c': 3}})
    # cls(test_normal_function).run()
    # =====================
    # ('success', {'a': 1.1, 'b': 2, 'c': False, 'd': 'string', 'e': 1, 'f': [1, 2, 3], 'args_dict': {'h': 3}})
    # cls(test_keyword_only_function,
    #     choices={
    #         'e': [1, 2, 3, 4, 5]
    #     },
    #     checkboxes={
    #         'f': [1, 2, 3, 4, 5]
    #     }).run()
    # =====================
    # cls(TestClass().test_method).run()
    # =====================
    # cls(TestClass().test_class_method).run()
    # =====================
    # cls(test_defaults, defaults={'a': 1}).run()
    pass

TODO

  • Terminal UI
  • GUI
  • Web UI (no need to do)

Metadata

Release files for ask4args 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for ask4args 0.3.0
File Interpreter ABI Platform
ask4args-0.3.0-py3-none-any.whl Python 3 none any Details

Release files / ask4args-0.3.0-py3-none-any.whl

Download URL ask4args-0.3.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2d0c4be2834bca7f227abc102b5721f38893b176f087ddbf77b4a41385ee50a
BLAKE2b-256 checksum
How to use checksums
d39c9acc0222cad78ea47e8b218753fe4b79df3797b31b84b8e62321d7a9231c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page