Skip to main content

Prompting library for terminals.

Project description

# interrogatio

Python versions PyPi Status Read the Docs Build Status codecov

A python library to prompt users for inputs in a terminal application.

What is interrogatio

interrogatio is a python 3.8+ library based on the python-prompt-toolkit and inspired by PyInquirer that help CLI developers to ask users for inputs.

Questions can be rendered onto the terminal prompt or as curses-like dialogs.

Documentation

interrogatio documentation is hosted on Read the Docs.

Getting started

Requirements

interrogatio depends on the python-prompt-toolkit library and its dependencies.

Installation

Using pip

$ pip install interrogatio

Extra dependencies

If you want to use the shell command with yml files you can install the yml dependency:

$ pip install interrogatio[yml]

Basic usage

interrogatio needs a list of questions to prompt the user for answers.

Each question is a python dictionary with at least the following keys:

  • name: it has to be unique within the list of questions. It represents the variable name;
  • type: the type of question;
  • message: the text of the prompt.

Optionally you should specify:

  • a default: a default value;
  • a validators: a list of children of Validator class
  • a values: a list of tuples (value, label) to provide a list of choices for the selectone or selectmany question types.

interrogatio can run into two modes: dialog and prompt.

Dialog mode

Dialog mode showcase

from interrogatio import dialogus

questions = [
    {
        'name': 'name',
        'type': 'input',
        'message': "What's your name ?",
        'description': 'Please enter your full name. This field is required.',
        'validators': [{'name': 'required'}],
    },
    {
        'name': 'birth_date',
        'type': 'date',
        'message': "What's your birth date ?",
        'description': 'Enter your birth date.',
    },
    {
        'name': 'nationality',
        'type': 'selectone',
        'message': "What's your nationality ?",
        'description': 'Please choose one from the list.',
        'validators': [{'name': 'required'}],
        'values': [
            ('IT', 'Italian'),
            ('ES', 'Spanish'),
            ('US', 'American'),
            ('UK', 'English'),
        ],
    },
    {
        'name': 'languages',
        'type': 'selectmany',
        'message': "What are your favorite programming languages ?",
        'description': 'Please choose your favorites from the list.',
        'values': [
            ('py', 'Python'),
            ('rb', 'Ruby'),
            ('js', 'Javascript'),
            ('go', 'Golang'),
            ('rs', 'Rust'),
            ('c', 'C'),
            ('cpp', 'C++'),
            ('java', 'Java'),
        ],
    },
]

intro = """<blue>Welcome to <b><i>interrogatio 2.0</i></b>!

This is the second major release of interrogatio with nice improvements.</blue>

<b>What's new</b>
<b>----------</b>

* Curses-like dialog experience had been completely rewritten.
* New questions handlers for dates, date ranges and masked inputs.
* Validators are now based on the <u>validators</u> library.
"""


answers = dialogus(questions, 'interrogatio showcase', intro=intro, summary=True)

Prompt mode

Prompt mode showcase

from interrogatio import interrogatio

questions = [
    {
        'name': 'name',
        'type': 'input',
        'message': "What's your name ?",
        'description': 'Please enter your full name. This field is required.',
        'validators': [{'name': 'required'}],
    },
    {
        'name': 'birth_date',
        'type': 'date',
        'message': "What's your birth date ?",
        'description': 'Enter your birth date.',
    },
    {
        'name': 'nationality',
        'type': 'selectone',
        'message': "What's your nationality ?",
        'description': 'Please choose one from the list.',
        'validators': [{'name': 'required'}],
        'values': [
            ('IT', 'Italian'),
            ('ES', 'Spanish'),
            ('US', 'American'),
            ('UK', 'English'),
        ],
    },
    {
        'name': 'languages',
        'type': 'selectmany',
        'message': "What are your favorite programming languages ?",
        'description': 'Please choose your favorites from the list.',
        'values': [
            ('py', 'Python'),
            ('rb', 'Ruby'),
            ('js', 'Javascript'),
            ('go', 'Golang'),
            ('rs', 'Rust'),
            ('c', 'C'),
            ('cpp', 'C++'),
            ('java', 'Java'),
        ],
    },
]


answers = interrogatio(questions)

Contributing

If you want to contribute to the project, you can submit bugs, feature requests or fork the github repository and submit your pull request.

License

interrogatio is released under the BSD 3-Clause "New" or "Revised" License.

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

interrogatio-2.3.1.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

interrogatio-2.3.1-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file interrogatio-2.3.1.tar.gz.

File metadata

  • Download URL: interrogatio-2.3.1.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Linux/5.15.0-1023-azure

File hashes

Hashes for interrogatio-2.3.1.tar.gz
Algorithm Hash digest
SHA256 195d89070592bb2c5e5361e531139ea61ffa220634074090d2a385903d804a15
MD5 60e9ddcb111e064f94ae09c32519ee09
BLAKE2b-256 a9d071bcff650e74354d3c10c4e15bf8dd97daa3b4ff9e73bb14285346225320

See more details on using hashes here.

File details

Details for the file interrogatio-2.3.1-py3-none-any.whl.

File metadata

  • Download URL: interrogatio-2.3.1-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Linux/5.15.0-1023-azure

File hashes

Hashes for interrogatio-2.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d145cbc83a5192c82e7f43bf2febcb939da40c2450e2591a4cb5d8d67c2bf956
MD5 03c12be176be9ad3cc13d0c93d9259e8
BLAKE2b-256 fa8fa34e8ded202c756f43eafd2fb37ebeb93b4a7fdd24110985a3274d2254b4

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