Skip to main content

Improved prompts for rich.

Project description

Supported Python Versions PyPI version

Downloads

English readme

better-rich-prompts is a Python extension library for Rich.

This Library makes it easy to use lists and dictionaries as choices for prompt.ask .

Compatibility

This library should work

Installing

python -m pip install better-rich-prompts

Using List Prompt

Example 1 - Using list of dictionaries

from better_rich_prompts.prompt import ListPrompt

choices = [
    {"name": "english", "language_code": "en"},
    {"name": "spanish", "language_code": "es"},
    {"name":"french","language_code":"fr"},
]
ListPrompt.ask("Select a language", choices, choice_key="name")

ListPrompt Example

Example 2 - Using list of strings

from better_rich_prompts.prompt import ListPrompt

choices = ["en", "es", "fr"]
ListPrompt.ask("Select a language", choices,default="en")

ListPrompt Example

Example 3 - Using list of custom objects

from better_rich_prompts.prompt import ListPrompt

class Language:
    def __init__(self, name, code):
        self.name = name
        self.code = code


choices = [
    Language("english", "en"),
    Language("spanish", "es"),
    Language("french", "fr"),
]
ListPrompt.ask(
    "Select a language", choices, default="en", choice_key=lambda c: c.code
)

ListPrompt Example

Using Dict Prompt

from better_rich_prompts.prompt import DictPrompt

choices = {"en":"english","es":"spanish","fr":"french"}
DictPrompt.ask("Select a language", choices)

ListPrompt Example

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

better_rich_prompts-1.0.2.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

better_rich_prompts-1.0.2-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page