Python code execution integration for data analysis, file processing, and automation tasks within Autohive workflows.
- Execute arbitrary Python code in a sandboxed environment
- Process input files (CSV, Excel, JSON, images, PDFs, etc.)
- Automatically detect and return generated output files
- Access to popular data science and document processing libraries
- Base64-encoded file transfer for binary data
No authentication required. This integration runs Python code locally.
Execute Python code with optional input files and automatic output file collection.
Inputs:
python_code(string, required): The Python code to executefiles(array, optional): Input files to make available to the scriptname(string): Filename (e.g., "data.csv")content(string): Base64-encoded file contentcontentType(string, optional): MIME type
Outputs:
result(string): Standard output from the executed codeerror(string, optional): Error message/traceback if execution failedfiles(array): Generated output filesname(string): Output filenamecontent(string): Base64-encoded file contentcontentType(string): MIME type
The following third-party libraries are pre-installed:
- numpy - Numerical computing
- Pillow - Image processing
- PyPDF2 - PDF manipulation
- python-docx - Word document creation/editing
- reportlab - PDF generation
- openpyxl - Excel file reading/writing
- XlsxWriter - Excel file creation
- matplotlib - Data visualization and plotting
- python-pptx - PowerPoint presentation creation
Plus the entire Python standard library.
# Input
python_code = """
result = sum([1, 2, 3, 4, 5])
print(f"Sum: {result}")
"""# Input
python_code = """
import csv
import json
with open('data.csv', 'r') as f:
reader = csv.DictReader(f)
data = list(reader)
# Calculate totals
total = sum(float(row['amount']) for row in data)
print(json.dumps({'total': total, 'count': len(data)}))
"""
files = [
{
"name": "data.csv",
"content": "<base64-encoded-csv>",
"contentType": "text/csv"
}
]# Input
python_code = """
import openpyxl
from openpyxl.styles import Font, Alignment
wb = openpyxl.Workbook()
ws = wb.active
ws.title = "Report"
# Add headers
ws['A1'] = 'Name'
ws['B1'] = 'Value'
ws['A1'].font = Font(bold=True)
ws['B1'].font = Font(bold=True)
# Add data
data = [('Item 1', 100), ('Item 2', 200), ('Item 3', 150)]
for i, (name, value) in enumerate(data, start=2):
ws[f'A{i}'] = name
ws[f'B{i}'] = value
wb.save('report.xlsx')
print("Report generated successfully")
"""# Input
python_code = """
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.figure(figsize=(10, 6))
plt.plot(x, y)
plt.title('Sine Wave')
plt.xlabel('X')
plt.ylabel('Y')
plt.grid(True)
plt.savefig('chart.png', dpi=150)
print("Chart saved")
"""# Input
python_code = """
from PIL import Image
# Open input image
img = Image.open('input.png')
# Convert and save as JPEG
img = img.convert('RGB')
img.save('output.jpg', 'JPEG', quality=85)
print(f"Converted image: {img.size}")
"""
files = [
{
"name": "input.png",
"content": "<base64-encoded-png>",
"contentType": "image/png"
}
]- Output results via print() - Any non-file results should be printed to stdout
- Save files to current directory - Output files are auto-detected from the working directory
- Use available libraries only - Don't import packages not in the pre-installed list
- Handle errors gracefully - Use try/except for robust scripts
- Close file handles - Use context managers (
withstatements) for file operations
autohive-integrations-sdk~=1.0.2numpyPillowPyPDF2python-docxreportlabopenpyxlXlsxWritermatplotlibpython-pptx
To run the tests:
- Navigate to the integration directory:
cd code-analysis - Install dependencies:
pip install -r requirements.txt -t dependencies - Run the tests:
python tests/test_code_analysis.py
1.0.0