pyiotools

0.3.18 · active · verified Sun Apr 12

pyiotools is a Python library that offers various utilities for handling I/O operations, including an IOHandler class for collecting input programmatically, via command-line, or GUI with an API similar to `argparse`. It also includes utilities for caching, serialization, and secret management. The library is actively maintained with frequent minor releases, currently at version 0.3.18, but is explicitly noted as being under active development with a warning that its API may undergo significant breaking changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the core `IOHandler` for defining and (simulated) parsing arguments, and the `Cache` utility for simple persistent key-value storage. It uses environment variables to make the example interactive and runnable.

import os
from iotools import IOHandler, Cache

# 1. Using IOHandler (similar to argparse)
# Create an IOHandler instance for input collection
program_io = IOHandler(
    'my_app', 
    'A simple application demonstrating iotools input handling.'
)
program_io.add_argument('--name', help='Your name', default='Guest')
program_io.add_argument('--verbose', action='store_true', help='Enable verbose output')

# In a real script, this would parse sys.argv.
# For programmatic quickstart, we simulate parsed arguments.
class MockArgs:
    def __init__(self, name, verbose):
        self.name = name
        self.verbose = verbose

# Use environment variables to make it runnable for testing
args = MockArgs(
    name=os.environ.get('IOT_NAME', 'User'),
    verbose=os.environ.get('IOT_VERBOSE', 'False').lower() == 'true'
)

print(f"Hello, {args.name}!")
if args.verbose:
    print("Verbose output enabled.")

# 2. Using Cache for persistent data storage
cache_name = os.environ.get('IOT_CACHE_NAME', 'my_app_data')
my_cache = Cache(cache_name)

# Put and get data
my_cache.put('favorite_color', os.environ.get('IOT_COLOR', 'blue'))
print(f"Favorite color from cache: {my_cache.get('favorite_color')}")

# Update data
my_cache.put('favorite_color', 'red')
print(f"Updated favorite color: {my_cache.get('favorite_color')}")

# Pop data
popped_color = my_cache.pop('favorite_color')
print(f"Popped favorite color: {popped_color}")
print(f"Is favorite_color still in cache? {my_cache.get('favorite_color', 'Not Found')}")

view raw JSON →