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}
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| invalid-0.0.1.tar.gz | 3.6 kB | Without provenance | Details for invalid-0.0.1.tar.gz |
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
|
Security for invalid 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.