Skip to main content

Kind of like a non intrusive addon for the standard input()

Project description

InputPowertools

Eliminate the annoyances of getting input or building a cli in python!

Prolog

I love using command line interfaces and I think most people like building these small tools as well, but its really annoying to have to build the interface between the user and your program, hence I build this python package to take care of this part for you.

Installation

$ pip install InputPowertools

Examples

input()

Alpha

>>> print(f"Result: {input('Type your name:', Mode.ALPHA)}")

Type your name:  >? 123
🛑 Please enter a value that is completely alphabetic (no punctuation, numbers, emojis or nothing)...
Type your name:  >? Malte
Result: Malte

Numeric

>>> print(f"Result: {input('How old are you:', Mode.NUMERIC, domain=lambda x: x % 1 == 0)}")

How old are you:  >? 😀
🛑 Please enter a number...
How old are you:  >? 13.5
🛑 Please enter a value that fits the answers domain...
How old are you:  >? 16
Result: 16

Options

>>> print(f"Result: {input('Are you a what kind of person are you?', Mode.OPTIONS, options=['Cat person', 'Dog person', 'Bird person'])}")

Are you a what kind of person are you? 
1 -> Cat person
2 -> Dog person
3 -> Bird person
Select option [1-3]:  >? Though question
🛑 Please enter a number...
Select option [1-3]:  >? 0
🛑 Please enter a value that fits the answers domain...
Select option [1-3]:  >? 4
🛑 Please enter a value that fits the answers domain...
Select option [1-3]:  >? 2
Result: (1, 'Dog person')

Regex

>>> print(f"Result: {input('What is your favorite hex color?', Mode.REGEX, regex=r'(#([a-fA-F0-9]{6}|[a-fA-F0-9]{3}))', regex_description='Hexadecimal Color. Something like #123 or #FF32CD')}")

What is your favorite hex color?  >? red
🛑 Please enter a value that fits this description: Hexadecimal Color. Something like #123 or #FF32CD
What is your favorite hex color?  >? #F00
Result: #F00

Defaults

Just pressing enter

>>> print(f"Result: {input('Type your name:', Mode.ALPHA, default='Hannes')}")

Type your name: (Hannes) >? 
Result: Hannes

Typing something else

>>> print(f"Result: {input('Type your name:', Mode.ALPHA, default='Hannes')}")

Type your name: (Hannes) >? Malte
Result: Malte

Confirm

>>> print(f"Result: {input('Type your name:', Mode.ALPHA, confrim=True)}")

Type your name:  >? Malte
Do you want to select "Malte"? 
1 -> yes
2 -> no
Select option [1-2]: (2) >? 1
Result: Malte

CLI

Guide

$  python examples/example\ 1.py

For more information: examples/example 1.py --help

Analysing the docstring and type hints to generate --help

$  python examples/example\ 1.py --help

Some function
  A function that is truly amazing... wow!
Return: Some fascinating thing
        Options:
                --help
                        Prints out information about the program.
                         Type:    bool
                         Default: False
                --a
                        Is a variable called a
                --b
                        Is a variable called b
                         Type:    str
                --c
                        Is a variable called c
                         Type:    list
                --d
                        Is a variable called d
                         Type:    bool
                         Default: False

Analysing the function parameters to generate cli

$ python examples/example\ 1.py  --a lol --b "this is a value with spaces" --c 4 2 "test123" --d

a='lol' b='this is a value with spaces' c=[4, 2, 'test123'] d=True

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

InputPowertools-1.0.1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

InputPowertools-1.0.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file InputPowertools-1.0.1.tar.gz.

File metadata

  • Download URL: InputPowertools-1.0.1.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11

File hashes

Hashes for InputPowertools-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9db39df8d3aadf15861f8d5ebafb2dd0d929362172488e9161069a443d9db63c
MD5 47668d78eb129f9137e89206ea201c65
BLAKE2b-256 53a6c22ed956043185224cd6a9f6b10bdd139661ea71898c270edddfaf1d1677

See more details on using hashes here.

File details

Details for the file InputPowertools-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: InputPowertools-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11

File hashes

Hashes for InputPowertools-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a46cd9fe3fbd9c2e7e904f4237d888e8542be2b544f5d95f365754f7644c8263
MD5 01fbc7deb0cc1134ce2fb75deafed993
BLAKE2b-256 bb7489d31b60bc1364f472b8d4a0816f5af9580845a44719d3d0d4640f368e9a

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