Skip to main content

A Python command line input and validation library

Project description

promptpy

A Python command-line input and validation library.

version Python Version from PEP 621 TOML coverage

promptpy prompts for and validates a range of different data types on the command line. Out of the box it supports limited character sets, integers, floats, dates, yes/no, lists and single-character commands:

from promptpy import Prompt

prompt = Prompt()
choice = prompt.integer("Pick a number", min=1, max=10, default=7)
# Prompt is displayed as:
# Pick a number (1-10) [7]:

The user will be reprompted with context-specific error messages until a valid integer is entered.

It is easy to add other types of prompt and validation by creating custom validators.

For more detail see the documentation.

Installation

(.venv) $ pip install promptpy

Examples

Options

from promptpy import Prompt

prompt = Prompt()
options = {
    's': 'to solve',
    'p': 'to play',
    'q': 'to quit',
}
choice = prompt.options(options, default='s')
# Prompt is displayed as:
# Enter S to solve, P to play, Q to quit [S]:

Yes/No

from promptpy import Prompt

prompt = Prompt()
choice = prompt.yes_no("Again", default="y")
# Prompt is displayed as:
# Again (Y/N)? [Y]:

Date

import datetime
from promptpy import Prompt

prompt = Prompt()
date = prompt.date('Enter a date (dd/mm/yyyy)', '%d/%m/%Y', default=datetime.date(2024, 1, 1))
# Prompt is displayed as:
# Enter a date (dd/mm/yyyy) [01/01/2024]:

See the Usage section of the documentation for a full list of methods, or the prompt module for details of methods and parameters.

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

promptpy-0.2.0.tar.gz (57.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

promptpy-0.2.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file promptpy-0.2.0.tar.gz.

File metadata

  • Download URL: promptpy-0.2.0.tar.gz
  • Upload date:
  • Size: 57.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for promptpy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 196e4fd73e721e895fcff02ccb4cc32a2d2f938c8bd6a52e18e95bbda3be9974
MD5 4c8a4836c8315216f11917ae54936cb3
BLAKE2b-256 4dd077de9ac0f43ac318cb665e11d8948e6145c8eda4178d3aeb3d4d00bd04b1

See more details on using hashes here.

File details

Details for the file promptpy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: promptpy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for promptpy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4dcb39027a6f551a2100634251923139d110ca12b4d4b662f6ad4b4a255b4105
MD5 e835deca39f47692453d9cf28b32fac9
BLAKE2b-256 ef671702ca2dab740e9f21b6aaf90dbb7158e1a8aaf18558f597dec1be19504f

See more details on using hashes here.

Supported by

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