Skip to main content

Automatically turn script arguments into an interactive terminal interface

Project description

Tooey

Turn any python console script into an interactive TUI application. Tooey is similar to (and inspired by) Gooey, but keeps you in the terminal.

Without Tooey 😕

Running a command line script without the Tooey decorator

With Tooey 🎉

Running a command line script with the Tooey decorator (sample)

Installation

Install Tooey from PyPi via pip:

python -m pip install tooey

Getting started

Decorate your script's argparse function with @Tooey, then run the script with or without any of its arguments. You'll be prompted interactively in the terminal to enter each argument. After this the script will continue as normal.

Example

The following python script requests and then prints three arguments. The method that handles command line arguments is decorated with @Tooey.

import argparse
from tooey import Tooey

@Tooey
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('positional', nargs=1, help='A positional argument requiring one value')
    parser.add_argument('--named-choices', nargs=2, type=int, choices=range(1, 5), help='A named argument requiring two integers from a given list of choices')
    parser.add_argument('--store-true', action='store_true', help='A store_true argument')
    print(parser.parse_args())

main()

Tooey automatically turns this into an interactive prompt for each argument. Running a command line script with the Tooey decorator (full)

Configuration

Tooey will automatically inject itself into any decorated functions whenever sys.isatty() is True.

If you would like to override this behaviour and disable Tooey when running a script, add the additional parameter --ignore-tooey when running, or set an environment variable IGNORE_TOOEY. For example, Tooey will ignore any decorated methods in this script:

$ python tooey_example.py val1 --named-choices 1 3 --ignore-tooey

Conversely, if you would like to force Tooey to inject itself into decorated functions even when it does not detect a terminal-like environment, add the additional parameter --force-tooey when running, or set an environment variable FORCE_TOOEY. For example, Tooey will still run in the following script:

$ FORCE_TOOEY=1 python tooey_example.py val1 --named-choices 1 3 | sort

License

Apache 2.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

tooey-0.3.0.tar.gz (11.4 kB view hashes)

Uploaded Source

Built Distribution

tooey-0.3.0-py3-none-any.whl (11.1 kB view hashes)

Uploaded Python 3

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