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
Metadata
Release files for iofx 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| iofx-0.1.1.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| iofx-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / iofx-0.1.1.tar.gz
| Download URL | iofx-0.1.1.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e4194e2794e7556eb76b6953b72acb8af93e0b7846896f64113b6167e53e81e9
|
|
BLAKE2b-256 checksum How to use checksums |
ac3019d68bf70e95a6510734a56e0ca62ce1b061e83718301465ab2d49c9fa37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.17.3 CPython/3.10.14 Linux/5.15.0-117-generic
|
Release files / iofx-0.1.1-py3-none-any.whl
| Download URL | iofx-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b08f6c3c2979c25c07d377f486f14c653ec4df26e43d9e0a5388cd5b42b154a6
|
|
BLAKE2b-256 checksum How to use checksums |
7adef0d821a86d6fa7e1deafd98e79be3d3d485eb33aed6d293c34709701d9e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.17.3 CPython/3.10.14 Linux/5.15.0-117-generic
|