Skip to main content

Python user input prompt toolkit

Project description

ASKpy is a module which makes collecting Raw Input for your Python program more robust. It supports creating prompts, conditional questions, validation, and transforming responses.


Installing ASKpy is as simple as:

pip install askpy


ASKpy at its core is a way to build up questions and create a prompt for users in your terminal applications.

from askpy import Prompt

prompt = Prompt()

my_question = prompt.make_question('name', 'What is your name?')



name = prompt.get_response('name')

While the above may hide raw input, it does not give you much more power than you could already use in the standard library. ASKpy allows you to validate and transform your responses easily:

from askpy import Prompt, Validator

prompt = Prompt()

question = prompt.make_question('age', 'How old are you?') \
                 .must(Validator.num_gt(20)) \



question = prompt.get_response('question')

The above example will ensure the user enters an age greater 20 otherwise it will reprompt them. Once it has a valid age it will cast it to an integer for you to use later.

There’s more too.

Sometimes questions depend on others and in order to handle these cases you would usually rely on conditional statements and parsing. With ASKpy you can do this by chaining questions.

from askpy import Prompt, ValidationError, Validator

prompt = Prompt()

def validate_even(num):
    if int(num) % 2 != 0:
        raise ValidationError('Please choose an even number')

def validate_odd(num):
    if int(num) % 2 == 0:
        raise ValidationError('Please choose an odd number')

even_or_odd = prompt.make_question('even_or_odd', 'Do you prefer even or odd numbers?') \
                    .must(Validator.one_of(['even', 'odd']))

even_question = prompt.make_question('even', 'What is your favorite even number?') \
                      .must(validate_even) \

odd_question = prompt.make_question('odd', 'What is your favorite odd number?') \
                     .must(validate_odd) \

prompt.add(even_or_odd) \
      .then(lambda resp: resp == 'even', even_question, odd_question)


As you can see, you get explicit prompts with the ability to keep your code sane.

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

askpy-0.0.4.tar.gz (6.4 kB view hashes)

Uploaded source

Built Distribution

askpy-0.0.4-py3-none-any.whl (8.1 kB view hashes)

Uploaded 3 5

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