simple-code-execution Documentation
simple-code-execution is a Python library for executing code predictions through subprocess and threading with comprehensive parallel processing, file management, and result handling.
Features
Parallel Execution: Execute multiple code predictions simultaneously using multiprocessing
File Management: Automatic writing and cleanup of temporary files
Robust Error Handling: Built-in timeout handling, syntax error detection, and graceful failure recovery
Flexible Configuration: Comprehensive configuration options for execution behavior
Result Processing: Powerful preprocessing and postprocessing pipeline for custom workflows
Resource Control: Memory and CPU usage monitoring with configurable limits
Quick Example
from code_execution import ExecutionConfig, execute_predictions, Executable, Command
# Configure execution
config = ExecutionConfig(num_workers=2, default_timeout=10)
# Define predictions
predictions = [{"code": "print('Hello, World!')"}]
# Execute with custom preprocessor
def preprocessor(pred):
return Executable(
files={"main.py": pred["code"]},
commands=[Command(command=["python3", "main.py"])]
)
results = execute_predictions(config, predictions, preprocessor)
Table of Contents
Getting Started:
API Reference:
Installation
Install using pip:
pip install simple-code-execution
Or install from source:
git clone https://github.com/gabeorlanski/simple-code-execution.git
cd simple-code-execution
pip install -e .
Requirements
Python 3.10+
psutil >= 5.9
numpy >= 1.26
aiofiles >= 22.1.0
tqdm >= 4.60.0
ujson >= 5.10.0
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.