iofx: I/O Effect Detection for Python Functions
iofx is a Python library that provides automated detection and validation of file I/O effects for
functions. It leverages Pydantic for type checking and effect validation.
Features
- Automatic detection of file read/write operations based on parameter types
- Runtime validation of file effects
- Integration with Pydantic for robust type checking
- Easy-to-use decorator for adding effect detection to functions
Installation
pip install iofx
Quick Start
from iofx import create_function_model
from pydantic import FilePath, NewPath
def process_file(input_path: FilePath, output_path: NewPath) -> None:
with open(input_path) as infile, open(output_path, "w") as outfile:
outfile.write(infile.read().upper())
# Create the function model
process_file_model = create_function_model(process_file)
# Usage
try:
result = process_file_model(
input_path="existing_input.txt",
output_path="new_output.txt",
)
print("File processed successfully")
except ValueError as e:
print(f"Effect check failed: {e}")
How It Works
create_function_modelanalyzes the function's signature and parameter types.- It automatically detects potential file I/O effects based on parameter annotations:
FilePath: Indicates a file read operationNewPath: Indicates a file write operation to a new filePath: Indicates a potential file append operation
- At runtime, it checks if the file operations are valid (e.g., input file exists, output file
doesn't exist for
NewPath).
API Reference
create_function_model(func: Callable[P, R]) -> FunctionModel[P, R]
Creates a FunctionModel instance for the given function, which wraps the original function with
effect detection and validation.
class FunctionModel(BaseModel, Generic[P, R])
func: The original functionparameters: List ofParameterInfoobjects describing function parametersreturn_type: Return type of the functioneffects: List ofFileEffectobjects describing detected file I/O effects
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
iofx-0.1.1.tar.gz
(3.9 kB
view details)
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
iofx-0.1.1-py3-none-any.whl
(4.4 kB
view details)
File details
Details for the file iofx-0.1.1.tar.gz.
File metadata
- Download URL: iofx-0.1.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
pdm/2.17.3 CPython/3.10.14 Linux/5.15.0-117-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4194e2794e7556eb76b6953b72acb8af93e0b7846896f64113b6167e53e81e9
|
|
| MD5 |
079c02c36c890a89c131cb5b85939988
|
|
| BLAKE2b-256 |
ac3019d68bf70e95a6510734a56e0ca62ce1b061e83718301465ab2d49c9fa37
|
File details
Details for the file iofx-0.1.1-py3-none-any.whl.
File metadata
- Download URL: iofx-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
pdm/2.17.3 CPython/3.10.14 Linux/5.15.0-117-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b08f6c3c2979c25c07d377f486f14c653ec4df26e43d9e0a5388cd5b42b154a6
|
|
| MD5 |
21b5de36220f141777b5f80298510e34
|
|
| BLAKE2b-256 |
7adef0d821a86d6fa7e1deafd98e79be3d3d485eb33aed6d293c34709701d9e6
|