Skip to main content

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

  1. create_function_model analyzes the function's signature and parameter types.
  2. It automatically detects potential file I/O effects based on parameter annotations:
    • FilePath: Indicates a file read operation
    • NewPath: Indicates a file write operation to a new file
    • Path: Indicates a potential file append operation
  3. 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 function
  • parameters: List of ParameterInfo objects describing function parameters
  • return_type: Return type of the function
  • effects: List of FileEffect objects 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)

Source distribution for iofx 0.1.1
File Size Uploaded
iofx-0.1.1.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iofx 0.1.1
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page