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.2.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.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: inp_kwargs-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 3a5ecdef72e8ad61d7ada09c7469c12c112cd28032409646a54b69ae54f50bb8
MD5 ed195703436b6a1ab24f07dded6d89c4
BLAKE2b-256 8cbf4575c55aede22ce26d9095e173b86777a51380e7274290a0c1e011b37fc3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: inp_kwargs-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d7964e6f359b837602ea0e5ccb74429c51ab96d43fe17b62262128597c085fc1
MD5 f4a4b8f70544139874c1001cd13b0a4e
BLAKE2b-256 30f745ca75032b7ad147ffa00b9ea166c363ed0bfd3b090ffa2cb09ae276e78b

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