Skip to main content

invalid

A small Python library and wrapper around pick to help remove the boilerplate around validating and processing command line input.

Installation

pip install invalid

Usage

>>> from invalid import prompt

Primitives

>>> age_prompt = prompt.Int("age")
>>> age_prompt.prompt()
Enter age: s
Invalid age 's'
Enter age: 28
28

Lists

>>> fruit_prompt = prompt.List(
...    "fruit",
...    ["apple", "banana", "orange"]
    )
>>> fruit_prompt.prompt()
Enter fruit:
-> apple
   banana
   orange
'apple'

ID to name mapping

>>> fruit_prompt = prompt.List(
...     "fruit",
...     {
...         "A crunchy apple": "apple",
...         "A sweet banana": "banana",
...         "A juicy orange": "orange"
...     }
... )
>>> fruit_prompt.prompt()
Enter fruit:
-> A crunchy apple
   A sweet banana
   A juicy orange
'apple'

Custom validation

>>> postcode_prompt = prompt.Text(
...     "postcode",
...     validate=lambda text: len(text) <= 5 and text.isnumeric()
... )
Enter postcode: 392838
Invalid postcode '392838'
Enter postcode: 0773
'0773'

Forms

>>> form = prompt.Form({
...     "name": prompt.Text("your full name"),
...     "dob": prompt.Text("your date of birth"),
...     "number": prompt.Text(
...         "your favourite number between 1 - 10",
...         validate=lambda num: 1 <= num <= 10
...     )
... })
>>> form.execute()
Enter your full name: John Doe
Enter your date of birth: 2 July 1987
Enter your favourite number between 1 - 10: 3
{'name': 'John Doe', 'date': '1987-07-02', 'number': 3}

Release files for invalid 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for invalid 0.0.1
File Size Uploaded
invalid-0.0.1.tar.gz 3.6 kB Details

Release files / invalid-0.0.1.tar.gz

Download URL invalid-0.0.1.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
87c5e330295211a16a9b4ea698ca88a518e28faca3aa29637f4d2edb909cb14b
BLAKE2b-256 checksum
How to use checksums
2eed7005370148b6679830ed237078415369733ba668e9a6a66e362879dec118
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page