Skip to main content

CI pipeline status PyPI PyPI - Python Version codecov Checked with mypy Code style: black

Columbo

Specify a dynamic set of questions to ask a user and get their answers.

columbo's feature set allows a program to:

  • Ask multiple types of questions:
    • Yes or No
    • Multiple choice
    • Open-ended
  • Validate the response provided by the user.
  • Use answers from earlier questions:
    • As part of the text of a question
    • As part of the text of a default value
    • To decide if a question should be skipped
  • Accept answers from the command line in addition to prompting the user.

Example

User Prompts

The primary use of columbo is to define a sequence of interactions that are used to prompt a user to provide answers using a terminal. Below is a sample which shows some ways this can be used.

import columbo

interactions = [
    columbo.Echo("Welcome to the Columbo example"),
    columbo.Acknowledge(
        "Press enter to start"
    ),
    columbo.BasicQuestion(
        "user",
        "What is your name?",
        default="Patrick",
    ),
    columbo.BasicQuestion(
        "user_email",
        lambda answers: f"""What email address should be used to contact {answers["user"]}?""",
        default="me@example.com"
    ),
    columbo.Choice(
        "mood",
        "How are you feeling today?",
        options={
            "happy": "😀",
            "sad": "😢",
            "sleepy": "🥱",
            "confused": "🤔",
        },
        default="happy",
    ),
    columbo.Confirm("likes_dogs", "Do you like dogs?", default=True),
]

answers = columbo.get_answers(interactions)
print(answers)

Below shows the output when the user accepts the default values for most of the questions. The user provides a different value for the email and explicitly confirms that they like dogs.

Welcome to the Columbo example
Press enter to start
 
What is your name? [Patrick]:

What email address should be used to contact Patrick? [me@example.com]: patrick@example.com

How are you feeling today?
1 - 😀
2 - 😢
3 - 🥱
4 - 🤔
Enter the number of your choice [1]:

Do you like dogs? (Y/n): y

{'user': 'Patrick', 'user_email': 'patrick@example.com', 'mood': 'happy', 'likes_dogs': True}

Command Line Answers

In addition to the interactive prompts, columbo can also parse command line arguments for interactions. This is done by changing columbo.get_answers() to columbo.parse_args(). Below shows the output when using the same interactions from above.

$ python columbo_example.py --user-email patrick@example.com --likes-dogs
{'user': 'Patrick', 'user_email': 'patrick@example.com', 'mood': 'happy', 'likes_dogs': True}
The full example
import columbo

interactions = [
    columbo.Echo("Welcome to the Columbo example"),
    columbo.Acknowledge(
        "Press enter to start"
    ),
    columbo.BasicQuestion(
        "user",
        "What is your name?",
        default="Patrick",
    ),
    columbo.BasicQuestion(
        "user_email",
        lambda answers: f"""What email address should be used to contact {answers["user"]}?""",
        default="me@example.com"
    ),
    columbo.Choice(
        "mood",
        "How are you feeling today?",
        options=["happy", "sad", "sleepy", "confused"],
        default="happy",
    ),
    columbo.Confirm("likes_dogs", "Do you like dogs?", default=True),
]

answers = columbo.parse_args(interactions)
print(answers)

Documentation

Check out the project documentation.

For an overview on how repository structure and how to work with the code base, read the Development Guide.

Credits

The development of this project was originally funded and incubated by Wayfair.

Metadata

Release files for columbo 0.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for columbo 0.14.0
File Size Uploaded
columbo-0.14.0.tar.gz 14.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for columbo 0.14.0
File Interpreter ABI Platform
columbo-0.14.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.8 kB

Release files / columbo-0.14.0.tar.gz

Download URL columbo-0.14.0.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8cb3d14c5269c6d6f207e83c0c3f347cdfd133fb52536f52c775cffd4f29a7ef
BLAKE2b-256 checksum
How to use checksums
cfca03e42aa3140568ac080cd2443d2f1789d1423f61e599808ab42dd6eb3b26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / columbo-0.14.0-py3-none-any.whl

Download URL columbo-0.14.0-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8cf13a09d14849fc1adac9e97d6b2bc0e8a928dfa3d9a3848d94e2d05c9636f8
BLAKE2b-256 checksum
How to use checksums
0a526630765a83d30d873f1da7a3c3f106604cfbc992d22405e6a7638859932a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

0.14.0 This release

2 release files

0.13.0

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.0.6

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page