Skip to main content

A library for easy input validation with kwargs

Project description

inp_kwargs

Easily validate user inputs with Python, no hassle required!

A Python library for easy input validation using kwargs. This library helps to easily validate inputs such as integers, strings, and more, without needing to write complex validation logic. Additionally, these functions prevent the program from crashing due to invalid inputs, ensuring a robust and user-friendly experience.

Example

Validating an Integer Input

from inp_kwargs import input_int

# Basic integer validation
# Ensures the program won't crash even if the user enters invalid data (e.g., a string).
test = input_int("Enter a number: ")
print(f"You entered: {test}")

# Request a number between 1 and 100
number = input_int("Enter a number between 1 and 100: ",
                   min_value=1,
                   max_value=100)

print(f"You entered: {number}")

# Request a number with custom error messages
number = input_int("Enter a number: ",
                   min_value=1,
                   max_value=100,
                   min_value_error_message="Error: Must be >= 1.",
                   max_value_error_message="Error: Must be <= 100.")
print(f"You entered: {number}")

Available Functions

1. input_int

Validate integer inputs with customizable criteria.

Parameters:

  • min_value (int, optional): Minimum value allowed.
  • max_value (int, optional): Maximum value allowed.
  • range (list, optional): Restrict input to a specific range of values.
  • allowed_values (list, optional): Accept only specific values.
  • even (bool, optional): Ensure the number is even.
  • odd (bool, optional): Ensure the number is odd.
  • multiple_of (int, optional): Validate input is a multiple of the given number.
  • type_error_message (str, optional): Error message for invalid type.
  • clear_console (bool, optional): Clears the console after each invalid input.

Example:

from inp_kwargs import input_int

number = input_int("Enter a number: ", min_value=1, max_value=10, even=True)
print(f"Validated number: {number}")

2. input_float

Validate float inputs with customizable criteria.

Parameters:

Similar to input_int, but for float values.

Example:

from inp_kwargs import input_float

number = input_float("Enter a decimal number: ", min_value=0.5, max_value=9.9)
print(f"Validated float: {number}")

3. input_str

Validate string inputs with customizable criteria.

Parameters:

  • strip (bool, optional): Remove leading and trailing spaces.
  • min_length (int, optional): Minimum string length.
  • max_length (int, optional): Maximum string length.
  • allowed_characters (str, optional): Restrict characters in input.
  • pattern (str, optional): Validate input using a regex pattern.
  • clear_console (bool, optional): Clears the console after each invalid input.
  • strip_error_message (str, optional): Message when string is empty after trimming.
  • min_length_error_message (str, optional): Error message for short strings.
  • max_length_error_message (str, optional): Error message for long strings.

Example:

from inp_kwargs import input_str

text = input_str("Enter a word: ", min_length=3, max_length=8, strip=True, allowed_characters="abcdefghijklmnopqrstuvwxyz")
print(f"Validated string: {text}")

Function Dictionary

Function Name Purpose Input Type
input_int Validate integer inputs Integer
input_float Validate float inputs Float
input_str Validate string inputs String

Features

  • Customizable validation for integers, floats, and strings.
  • Supports custom error messages or default messages for ease of use.
  • Clears the console between attempts for a clean interface.
  • Handles common validation needs such as ranges, patterns, and allowed values.

Installation

You can install inp_kwargs directly from PyPI:

pip install inp_kwargs

License

MIT License. See the LICENSE file for more details.

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

inp_kwargs-1.0.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

inp_kwargs-1.0.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file inp_kwargs-1.0.0.tar.gz.

File metadata

  • Download URL: inp_kwargs-1.0.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.0

File hashes

Hashes for inp_kwargs-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9087dfca193b89e31ef0c4871cd57c8576859d71d12177982703af3657a0f0c3
MD5 ac55acb4bbb5fc5a816ab8f43f614c16
BLAKE2b-256 d1cbd24049eb01de116fb753590b32753c2750c14efd627bbe05f506fb5bcabe

See more details on using hashes here.

File details

Details for the file inp_kwargs-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: inp_kwargs-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.0

File hashes

Hashes for inp_kwargs-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 971709ffd63937163ef9aa50964d27d0236af849ac6b6bc7db2bb1bec2a46e53
MD5 3ffab22005d14444903fd2dc4460f1b7
BLAKE2b-256 d5f9ce9d71d1cc038d3737972eddfe3d29f22887bbd6205acae13fde7e76ad67

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