File: index.md

package info (click to toggle)
python-inquirerpy 0.3.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,088 kB
  • sloc: python: 9,463; makefile: 15
file content (188 lines) | stat: -rw-r--r-- 4,180 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# InquirerPy

```{include} ../README.md
:start-after: <!-- start intro -->
:end-before: <!-- end intro -->
```

![Demo](https://assets.kazhala.me/InquirerPy/InquirerPy-demo.gif)

## Install

```{admonition} Requirements
python >= 3.7
```

```
pip3 install InquirerPy
```

## Basic Usage

`InquirerPy` provides two types of syntax that you can choose to use: [Classic syntax](#classic-syntax-pyinquirer) and [Alternate Syntax](#alternate-syntax).

```{Tip}
For any new users, [Alternate Syntax](#alternate-syntax) is recommended as its more flexible and extensible.
```

```{Note}
Checkout the sidebar on the left for detailed explanation and usage.
```

### Classic Syntax (PyInquirer)

```{Note}
Syntax ported from [PyInquirer](https://github.com/CITGuru/PyInquirer) which allows easy transition between the two projects.
Checkout [migration guide](#migrating-from-pyinquirer).
```

```{eval-rst}
The :ref:`pages/prompt:prompt` function takes a list of questions and return the result.
Each question should be an instance of :class:`dict`. Different types of `prompt` could require different keys, please
refer to individual `prompt` documentation for detailed explanation.
```

As a rule of thumb, each question requires a `type` (type of prompt) and `message` (question to ask) key. For any `prompt`
involving lists, a `choices` (list of available choices) key is also required.

Optionally provide a `name` key, `prompt` will store the result under the provided name key in the final result. If
no `name` key is provided, the index of the question will be used.

```python
from InquirerPy import prompt

questions = [
    {"type": "input", "message": "What's your name:", "name": "name"},
    {
        "type": "list",
        "message": "What's your favourite programming language:",
        "choices": ["Go", "Python", "Rust", "JavaScript"],
    },
    {"type": "confirm", "message": "Confirm?"},
]
result = prompt(questions)
name = result["name"]
fav_lang = result[1]
confirm = result[2]
```

### Alternate Syntax

Alternate syntax directly interact with individual `prompt` classes. It's more flexible, easier to customise
and also provides IDE type hintings/completions.

```python
from InquirerPy import inquirer

name = inquirer.text(message="What's your name:").execute()
fav_lang = inquirer.select(
    message="What's your favourite programming language:",
    choices=["Go", "Python", "Rust", "JavaScript"],
).execute()
confirm = inquirer.confirm(message="Confirm?").execute()
```

## Detailed Usage

```{admonition} Info
Please visit the sidebar on the left.
```

## Running Examples

`InquirerPy` provides several examples that you can run and play around.

1. Clone the repository

```
git clone https://github.com/kazhala/InquirerPy.git
cd InquirerPy
```

2. Create a Virtual Environment (Recommended)

```
python3 -m venv venv
source venv/bin/activate
```

3. Install dependencies

```
pip3 install -r examples/requirements.txt
```

4. View all available examples

```{Warning}
`demo_alternate.py` and `demo_classic.py` requires [boto3](https://github.com/boto/boto3) package and setup AWS credentials.
```

```
ls examples/*.py
ls examples/classic/*.py
ls examples/alternate/*.py
```

5. Edit and run any examples of your choice

```
python3 -m examples.classic.rawlist
# or
python3 examples/classic/rawlist
```

```{include} ../README.md
:start-after: <!-- start migration -->
:end-before: <!-- end migration -->
```

```{toctree}
:caption: prompts
:hidden:

pages/prompts/input.md
pages/prompts/secret.md
pages/prompts/filepath.md
pages/prompts/number.md
pages/prompts/confirm.md
pages/prompts/list.md
pages/prompts/rawlist.md
pages/prompts/expand.md
pages/prompts/checkbox.md
pages/prompts/fuzzy.md
```

```{toctree}
:caption: Customisation
:hidden:

pages/style.md
pages/kb.md
pages/height.md
pages/env.md
pages/dynamic.md
pages/raise_kbi.md
```

```{toctree}
:caption: API
:hidden:

pages/inquirer.md
pages/prompt.md
pages/validator.md
pages/separator.md
pages/patched_print.md
pages/color_print.md
```

```{toctree}
:caption: Reference
:hidden:

pages/faq.md
pages/api.md
pages/changelog.md
GitHub Repository <https://github.com/kazhala/InquirerPy>
```