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.2.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

tooey-0.2.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file tooey-0.2.0.tar.gz.

File metadata

  • Download URL: tooey-0.2.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.9

File hashes

Hashes for tooey-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b91acca2d4c06343ecd2123e838504ab796e83926be19b373c7d2a600d2a22e2
MD5 d77232a22887e3536b756744609e4e29
BLAKE2b-256 6fda255989568ab453eb361e11ef044090adc08463416cd9d5f71f40761cbc82

See more details on using hashes here.

File details

Details for the file tooey-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tooey-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.9

File hashes

Hashes for tooey-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 084098f9e8e62c757fd2cba542ec96fbc9a483b4c629e95f30ed933babe45d88
MD5 0d3fa99bab915b23e33f3c379c3473e9
BLAKE2b-256 864bce699be051f5d9b43a8496708ab7afdac983033fc9c3ffd3127a5e0e7db4

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