cli-interview-kit
Build Python command-line tools whose prompts are declared once and answered in three ways:
- at the terminal, as an interview that validates every answer and asks again until it is right;
- by flags, because every question has one, so the same command runs in CI and scripts;
- by an AI assistant:
--questionsprints the interview as JSON, the assistant asks the user in its own chat and runs the command with their answers.
from cli_interview_kit import App, Command, Interview, Question
NEW = Command(
name="new",
help="Create a project.",
interview=Interview(
questions=(
Question(
key="name",
section="project",
kind="text",
prompt="Project name",
help="The project's name.",
required=True,
),
Question(
key="template",
section="project",
kind="select",
prompt="Template",
help="What the project starts from.",
choices=("library", "service"),
default="library",
),
),
),
run=lambda invocation: print(invocation.answers),
)
APP = App(name="projects", description="Create projects.", version="1.0.0", commands=(NEW,))
if __name__ == "__main__":
raise SystemExit(APP.main())
$ projects new # a person at a terminal is interviewed
? Project name demo
? Template service
{'name': 'demo', 'template': 'service'}
$ projects new --yes --name demo # nobody to ask: flags and defaults
{'name': 'demo', 'template': 'library'}
$ projects new --yes # an answer with no safe default fails
ERROR --name is required: it has no safe default, so pass it when the run cannot prompt.
$ projects new --questions # what an AI assistant reads
{ "version": 1, "command": "projects new --yes", "procedure": [...], "questions": [...] }
Status: alpha (0.x). The API may change between minor versions; see the
changelog.
Install
uv add cli-interview-kit
# or: pip install cli-interview-kit
Requires Python 3.11 or newer, on Linux, macOS or Windows. It builds on argparse, questionary and rich.
A complete example using every feature is in
examples/projects.py.
From a clone, run just example new or just example new --questions.
Concepts
| You declare | What it is |
|---|---|
App |
The program: its name, version and commands. App.main() parses, runs and returns the exit code. |
Command |
One command: plain Options, an Interview, a run function, and any subcommands. |
Interview |
The command's Questions in order, the Consents it may ask for, and the sources of dynamic choices and defaults. |
Question |
One answer the command needs. Its flag is derived from its key (max_workers is --max-workers). |
Consent |
A confirmation before something hard to undo, such as deleting. Given by --yes, never by a default. |
Option |
A flag that chooses what the command does (--dry-run) rather than an answer the user could be asked. |
The run function receives an Invocation with the answers, the options, the console to
print and ask through, and the interaction to pass to Consent.ask.
Question kinds
kind |
Answer | Flag |
|---|---|---|
text |
str |
--flag VALUE |
select |
one of choices |
--flag CHOICE |
multiselect |
list[str]; every choice if omitted |
repeat --flag CHOICE |
confirm |
bool |
--flag or --no-flag |
int |
int or None |
--flag NUMBER |
list |
list[str] |
repeat --flag VALUE |
pairs |
dict[str, str] |
repeat --flag KEY=VALUE |
per_item |
dict[str, str], one value per item of a source |
repeat --flag ITEM=VALUE |
custom |
whatever your CustomKind parses |
your CustomKind.flag_form |
A question can also have:
- conditions:
when_all=(when("template", "service"),)asks it only when an earlier answer, an option or a derived fact matches. A flag for a question that does not apply fails the run. - a default, which may reference earlier answers (
default="{name}_pkg"), or adefault_fromsource.required=Truemeans it has no safe default. - a validator: any function that returns the value or raises
ValueErrorwith a message. Built in:non_empty,whole_number,byte_size. - dynamic values:
choices_from,items_fromandsuggestions_fromname a function inInterview.choicesthat returns the current values.suggestions_fromlists values under a free-text input as you type, without enforcing them. - a group: questions with safe defaults can share a
group, so an assistant asks "keep these defaults?" once instead of asking each.
Mistakes in a declaration, such as a select without choices or a reference to an undeclared
source, raise pydantic's ValidationError when the module is imported, not when a user runs the
command.
Who answers
Each run decides once whether it may prompt: it may when stdin is a terminal and --yes was not
given.
- At a terminal, each applicable question its flag did not answer is asked. An invalid answer shows its error under the input and is asked again.
- When nobody can be asked (
--yes, CI, a pipe), each question takes its default. One with no safe default fails the run, naming its flag. - Consents are given by
--yes. Without it they are asked at a terminal; with nobody to ask, a consent with asafe_defaulttakes it, and any other fails the run, asking for--yes. A piped stdin never consents by itself. Asking for a consent the command did not declare raisesDeclarationError, so--questionsalways lists every consent.
AI assistants
--questions prints the command's interview as a JSON document: every question with its
choices, defaults, conditions and current local values, the groups, the consents, the plain
options, and a procedure for the assistant to follow. Any assistant that can run a shell
command can use it, whichever product it is:
- It runs
projects new --questions. - It asks the user the questions in its own chat, skipping those whose conditions do not hold, and describes each consent.
- It runs
projects new --yes --name demo --template service. If the command rejects a value, it asks that question again.
Point your assistant at the command in your repository's agent instructions, for example: "To
create a project, run projects new --questions and follow its procedure." The document has a
version, raised when a field changes meaning or is removed.
Output and errors
Console.print writes a command's result to stdout. Status lines (info, success, warning,
error) and progress bars go to stderr, so output can be piped. Status lines are plain text:
values a user typed are never interpreted as rich markup.
| Outcome | Exit code |
|---|---|
| Success | 0 |
CliError, or an exception type listed in App.expected_errors: its message |
1 |
Any other exception: one line naming it, or the traceback with --debug |
1 |
Ctrl-C: Aborted. |
130 |
| Usage error (unknown flag, invalid choice) | 2 |
More
- Documentation: the API reference, generated from the docstrings, plus requirements, design and the changelog.
- Requirements: what the package must do, what it deliberately does not, and how each is verified.
- Design: how it works, the module map, decisions and trade-offs.
- Contributing: setup, checks and the release process.
- Security: how to report a vulnerability.
License
MIT, see LICENSE.
Metadata
Release files for cli-interview-kit 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cli_interview_kit-0.1.3.tar.gz | 82.3 kB | With provenance | Details for cli_interview_kit-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cli_interview_kit-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for cli_interview_kit-0.1.3-py3-none-any.whl |
Total release size: 115.9 kB
Release files / cli_interview_kit-0.1.3.tar.gz
| Download URL | cli_interview_kit-0.1.3.tar.gz |
|---|---|
| Size | 82.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5085a065c16bb263bd4ae036a148010f993a1cc0b1ac703baa24dcda9d08a227
|
|
BLAKE2b-256 checksum How to use checksums |
b5a8b8d1c66cc6a9e08e1f5b077d7b50f10ef270b019309a79dd4b2a783d4b1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logRelease files / cli_interview_kit-0.1.3-py3-none-any.whl
| Download URL | cli_interview_kit-0.1.3-py3-none-any.whl |
|---|---|
| Size | 33.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
070e0e5f15d801def869d3e0a812b6862f47133d40d6a04d3200d6f0e00cece7
|
|
BLAKE2b-256 checksum How to use checksums |
c0438adefba37de3a42bc7290202636da9682576a9c4dc5e8e239656a1fdf9e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logSecurity for cli-interview-kit 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for cli_interview_kit-0.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.