Registry / devops / survey

survey

JSON →
library5.4.2pypypi✓ verified 83d ago

A simple library for creating beautiful interactive prompts in the terminal. Current version is 5.4.2 (released April 2024). It supports various prompt types like text, list, checkbox, confirm, and path. The library is in active development with a focus on minimal dependencies and ease of use.

pip install survey
INSTALL
IMPORT
SIG · SURVEY
S
survey
devopspythonv5.4.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

survey
import survey
The correct import is simply 'import survey'. No submodule.
Text
from survey import Text
from survey.prompts import Text
In earlier versions (<=4.x), the path was survey.prompts. In 5.x, all prompts are in the top-level module.
List
from survey import List
from survey.prompts import List
Same as above.
survey.runners
from survey import run
from survey.runners import run
Runner functions are also at top-level in 5.x.
Answers
from survey import Answers
from survey.utils import Answers
Answers class is in top-level module since v5.

Creates a single text prompt and prints the answer.

import os from survey import Text, run name = os.environ.get('NAME', 'World') question = Text('What is your name?') answers = run(question) print(f'Hello, {answers[question.key]}!')
Debug
Known issues
breakingSurvey 5.0 completely reworked the API. Old code using survey.prompts, survey.runners, or survey.questions will not work. All prompts are now directly under the survey module, and the run function is top-level.
fix
Change 'from survey.prompts import ...' to 'from survey import ...'. Replace 'survey.runners.run(...)' with 'run(...)' after 'from survey import run'.
affects: >=5.0.0
breakingIn Survey 5.x, the 'Answers' object no longer supports direct attribute access (e.g., answers.my_key). You must use answers[question.key] or answers.get(question.key).
fix
Replace 'answers.my_key' with 'answers[question.key]'.
affects: >=5.0.0
gotchaThe 'run' function does not accept a list of prompts directly. You must pass the prompts as individual arguments or use the * operator.
fix
Use 'run(prompt1, prompt2)' or 'run(*[p1, p2])' instead of 'run([p1, p2])'.
affects: >=5.0.0
deprecatedThe 'survey.runners' module and 'survey.prompts' module are deprecated since v5.0 and will be removed in a future version.
fix
Import from top-level 'survey' instead.
affects: >=5.0.0
Errors
Common errors & fixes
AttributeError: module 'survey' has no attribute 'prompts'
Survey 5.x moved all prompts to the top-level. Importing from survey.prompts fails.
fix
Use 'from survey import Text' instead of 'from survey.prompts import Text'.
TypeError: run() takes 0 positional arguments but 1 was given
run() expects separate arguments, not a list.
fix
Call 'run(*prompts)' or 'run(prompt1, prompt2)'.
AttributeError: 'Answers' object has no attribute 'my_prompt'
In v5, answers object does not support attribute access. Use dictionary-style access.
fix
Use 'answers[question.key]' instead of 'answers.my_prompt'.
Upgrade
Version history
5.4.2latest on PyPI · released Oct 21, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
survey — pip install survey · libregistry