Enhanced I/O Library for Python
Project description
## Kipio - Enhanced I/O Library for Python
A complete I/O solution packed into 88 elegant lines of Python code. Kipio provides enhanced input and output functions with validation, security features, and file operations.
## Overview
Kipio is a lightweight yet powerful I/O library that simplifies user input and output operations in Python. It's designed for developers who need robust I/O handling without external dependencies.
## Installation
```bash
pip install kipio
Quick Start
from kipio import input_, print_
# Enhanced input with validation
name = input_("Enter your name: ", required=True)
# Enhanced output with timestamp
print_(f"Hello {name}!", timestamp=True)
Core Features
Enhanced Input (input_())
· Input validation with allowed choices · Default values and required fields · Hidden input for passwords (masked) · Case normalization and whitespace stripping · Byte encoding support
Enhanced Output (print_())
· File operations (read/write/append) · Timestamp auto-insertion · Silent mode for logging · Return as string or bytes · Custom separators and endings
Complete Documentation
input_() Function
def input_(prompt="", _bytes_=False, strip=True, lower=False, default=None,
choices=None, encoding="utf-8", required=False,
show_choices=False, hidden=False, mask_char="*"):
"""
Enhanced input function with comprehensive options.
Parameters:
-----------
prompt : str
Display text before input
_bytes_ : bool
Return bytes instead of string
strip : bool
Strip whitespace from input
lower : bool
Convert input to lowercase
default : any
Default value if input is empty
choices : list
List of allowed input values
required : bool
Raise error if input is empty
show_choices : bool
Display available choices in prompt
hidden : bool
Hide input (for passwords)
mask_char : str
Character to display for hidden input
Returns:
--------
str or bytes : User input
"""
print_() Function
def print_(*values, file=None, mode=None, end="\n", sep=" ", flush=False,
silent=False, timestamp=False, return_string=False,
encOD='utf-8', _bytes_=False):
"""
Enhanced print function with file operations.
Parameters:
-----------
*values : any
Values to print
file : str
File path for file operations
mode : str
File mode: 'r' (read), 'w' (write), 'a' (append), 'x' (exclusive create)
end : str
String appended after the last value
sep : str
String inserted between values
flush : bool
Whether to forcibly flush the stream
silent : bool
Don't print to console (useful for file-only operations)
timestamp : bool
Add timestamp before message
return_string : bool
Return string instead of printing
encOD : str
Encoding for bytes conversion
_bytes_ : bool
Return bytes instead of string
Returns:
--------
None, str, or bytes : Depending on parameters
"""
Usage Examples
Basic Usage
from kipio import input_, print_
# Simple input with validation
age = input_("Enter your age: ", required=True)
# Input with choices
color = input_("Favorite color: ",
choices=["red", "green", "blue"],
show_choices=True)
# Output to console and file
print_("Processing data...", timestamp=True)
print_("Results:", 42, 3.14, sep=" | ")
Security Features
# Password input
password = input_("Password: ", hidden=True, mask_char="•")
# Confirmation
confirm = input_("Confirm password: ", hidden=True, required=True)
File Operations
# Write to file
print_("Log entry", file="app.log", mode="a", timestamp=True)
# Read from file
content = print_("", file="config.txt", mode="r", return_string=True)
# Silent logging (file only)
print_("Debug info", file="debug.log", mode="a", silent=True)
Advanced Features
# Return as string
message = print_("Hello", "World", sep=", ", return_string=True, silent=True)
# Return as bytes
data = print_("Binary data", _bytes_=True, return_string=True)
# Complex input with all options
config = input_("Setting: ",
default="default_value",
choices=["option1", "option2", "default_value"],
show_choices=True,
lower=True,
required=True)
Real-World Scenarios
Configuration Setup
config = {
"username": input_("Username: ", required=True),
"theme": input_("Theme: ",
choices=["dark", "light", "auto"],
default="dark",
show_choices=True),
"notifications": input_("Enable notifications? ",
choices=["yes", "no"],
default="yes") == "yes"
}
CLI Application
def main_menu():
while True:
print_("\n=== MAIN MENU ===")
print_("1. Add User")
print_("2. View Logs")
print_("3. Settings")
print_("4. Exit")
choice = input_("Select (1-4): ",
choices=["1", "2", "3", "4"],
required=True)
if choice == "4":
print_("Goodbye!", timestamp=True)
break
Error Handling
Kipio includes built-in error handling:
try:
result = input_("Enter value: ", required=True)
except Exception as e:
print_(f"Error: {e}")
# Or handle errors returned as string
result = print_("", file="nonexistent.txt", mode="r", return_string=True)
if "Error:" in result:
print_("File not found")
Performance
· Zero external dependencies · Minimal memory footprint · Efficient 88-line implementation · Compatible with Python 3.7+
Testing
Test files are available in the examples/ directory:
# Run basic example
python examples/basic_usage.py
# Test all features
python examples/advanced_features.py
Contributing
Kipio is developed as part of the kiux-tools collection. Issues and contributions are welcome.
Version History
· 1.0.0 - Initial release with complete I/O functionality
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Developed by kiux-tools - Cybersecurity and development labs.
Links
· PyPI: https://pypi.org/project/kipio/ · Source Code: https://github.com/kiux-tools/kipio
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kipio-1.0.0.tar.gz.
File metadata
- Download URL: kipio-1.0.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a3c5fd654ef0e8e5b2168b1997a872bed4a1b97f46e5ac5fe39b9ed5ee6cac5
|
|
| MD5 |
867e4d2ae3a7a31e5308d7efb9ca63d9
|
|
| BLAKE2b-256 |
c02dbea2899859c5664e6f70c2076e6b12526a7dc09a53978d0427dbd5debe04
|
File details
Details for the file kipio-1.0.0-py3-none-any.whl.
File metadata
- Download URL: kipio-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18b076399ecf4fc51d6a37b04fdbb666c9928d19bef7aeb24679a0c2bbc2519b
|
|
| MD5 |
9f6560f882d0ff6ebd331ecf6fe0ab12
|
|
| BLAKE2b-256 |
19b0b42d0c0015ae7ddf6bc38514b61159ea57e1b0ed57c272b40a27b6cc810b
|