Skip to main content

Effortlessly turn any ArgumentParser script into an interactive prompt.

Project description

InteractiveArgparse

Coverage Build Status PyPI version

Table of Contents

Installation

To install, run

pip install InteractiveArgparse

Getting Started

You can wrap your existing ArgumentParser with an InteractiveArgumentParser like so:

import argparse
from interactive_argparse import InteractiveArgumentParser

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--name", help="The user's name.")
    parser.add_argument("--should_greet", help="Whether or not I should greet the user", action="store_true")

    iparser = InteractiveArgumentParser(parser)
    args = iparser.parse_args()
    print(args)


if __name__ == "__main__":
    main()

Running this script without arguments results in interactive prompts like so:

Example 1 output

Prompters

InteractiveArgumentParser can be pointed at a completely different interactive flow via its prompter argument: a rich-based terminal prompter (RichPrompter), an auto-generated web form (WebPrompter), or your own custom Prompter subclass.

from interactive_argparse import interactive


@interactive("rich")
def build_parser():
    parser = argparse.ArgumentParser()
    parser.add_argument("--name", help="The user's name.")
    return parser


args = build_parser().parse_args()

See docs/prompters.md for how to use the built-in prompters and how to write your own.

Subcommands

ArgumentParser.add_subparsers() is supported: InteractiveArgumentParser prompts for a subcommand first, then prompts for that subcommand's own arguments.

See docs/subparsers.md for details.

Development

Running tests

To run all tests:

python -m pytest

Contributing

We welcome early adopters and contributors to this project! See the Contributing section for details.

License

This project is open-sourced under the MIT license. See LICENSE for details.

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

interactiveargparse-0.2.0.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

interactiveargparse-0.2.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: interactiveargparse-0.2.0.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for interactiveargparse-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c5f034e85e596c16f83afef07e624f04ae55c1ec0a1b242e74ab4983f079d309
MD5 bd064831ddad60c7308949cc1d6f1732
BLAKE2b-256 066f8f75ba7ffc85238710e9aae1eb9bb0406aed6f8f6b90e79560568393de5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for interactiveargparse-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7aeee6616f86e6e698c2fb5688b0bea125efbcbe0d198c20f2c194bd09cfb73
MD5 e65d5c30f788e4231ab5394f4fb44958
BLAKE2b-256 7476eec994eb40004f2c1a904fe938789fdf0261f024538068fda44e45dd17a6

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