{"library":"questionary","title":"questionary","description":"Questionary is a Python library for effortlessly building elegant command line user prompts. It simplifies querying users for input in CLI applications, offering various question types like text, password, select, checkbox, and confirmation prompts. As of its current version 2.1.1, it is actively maintained with regular updates.","status":"active","version":"2.1.1","language":"en","source_language":"en","source_url":"https://github.com/tmbo/questionary","tags":["CLI","prompt","interactive","forms","input","command-line-interface"],"install":[{"cmd":"pip install questionary","lang":"bash","label":"Standard Installation"}],"dependencies":[],"imports":[{"symbol":"questionary","correct":"import questionary"},{"note":"While 'questionary' itself is the main import, specific classes like 'Choice' are typically imported directly from the top-level package.","wrong":"import questionary.Choice","symbol":"Choice","correct":"from questionary import Choice"},{"symbol":"Validator, ValidationError","correct":"from questionary import Validator, ValidationError"},{"note":"Use `prompt` for a list of questions defined as dictionaries, or direct `questionary.<type>().ask()` for single questions.","symbol":"prompt","correct":"from questionary import prompt"}],"quickstart":{"code":"import questionary\n\ndef main():\n    name = questionary.text(\"What's your name?\").ask()\n    if name is None: # User pressed Ctrl+C\n        print(\"Operation cancelled.\")\n        return\n\n    choice = questionary.select(\n        \"What do you want to do?\",\n        choices=['Order a pizza', 'Make a reservation', 'Ask for opening hours']\n    ).ask()\n    if choice is None:\n        print(\"Operation cancelled.\")\n        return\n\n    print(f\"Hello, {name}!\")\n    print(f\"You chose: {choice}\")\n\nif __name__ == \"__main__\":\n    main()","lang":"python","description":"This quickstart demonstrates how to use `questionary.text` for free-form input and `questionary.select` for choosing from a list. It also includes basic handling for `Ctrl+C` which causes `ask()` to return `None`."},"warnings":[{"fix":"Explicitly cast the returned value to the expected type, or ensure string values are handled correctly in your application logic. Always pass string values to `Choice(..., value='...')` if you require string output, or handle the type conversion after `ask()`.","message":"Between versions 1.6.0 and 1.8.0, the `value` parameter in `Choice` objects began to be implicitly type-cast to `str` upon selection. Applications expecting non-string types (e.g., `int`) to be returned from `select` or `checkbox` prompts may encounter `TypeError` or incorrect logic.","severity":"breaking","affected_versions":">=1.8.0"},{"fix":"Upgrade your Python environment to 3.8 or a later compatible version.","message":"Support for Python 3.6 and 3.7 was officially deprecated with the release of version 2.0.0. Projects using these older Python versions should upgrade to Python 3.8 or newer.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Perform validation on the list of selected items *after* the `checkbox().ask()` call has returned. You can iterate through the list and apply custom validation logic.","message":"The `checkbox()` prompt does not support the `validate` argument. Attempts to pass a `Validator` or validation function to `checkbox()` will result in an error or unexpected behavior.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always check for `None` as a possible return value after calling `.ask()` on any prompt type to gracefully handle user cancellation (e.g., `if answer is None: print('Cancelled'); exit()`).","message":"Pressing `Ctrl+C` (KeyboardInterrupt) during a prompt will cause `questionary.ask()` methods to return `None` instead of raising an exception. This needs to be explicitly handled in your code if you want to differentiate between user cancellation and a valid answer.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When using `questionary.form()`, pass `questionary.<type>(...).ask()` instances directly to keyword arguments. When using `questionary.prompt()`, provide a list of dictionaries, each defining 'type', 'name', and 'message' keys at a minimum. Refer to the documentation for correct usage of each.","message":"There are two main ways to ask multiple questions: `questionary.form()` which takes keyword arguments where values are `Question` instances, and `questionary.prompt()` which takes a list of question dictionaries. Mixing these patterns or using the wrong input format for the respective function can lead to errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-05T00:00:00.000Z","next_check":"2026-07-04T00:00:00.000Z"}