python-executor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Python Code Executor

Python代码执行器

Python Code Executor
Execute Python code in a safe, sandboxed environment with 100+ pre-installed libraries.
Python Code Executor
在预装了100+个库的安全沙箱环境中执行Python代码。

Quick Start

快速开始

bash
curl -fsSL https://cli.inference.sh | sh && infsh login
bash
curl -fsSL https://cli.inference.sh | sh && infsh login

Run Python code

Run Python code

infsh app run infsh/python-executor --input '{ "code": "import pandas as pd\nprint(pd.version)" }'
undefined
infsh app run infsh/python-executor --input '{ "code": "import pandas as pd\nprint(pd.version)" }'
undefined

App Details

应用详情

PropertyValue
App ID
infsh/python-executor
EnvironmentPython 3.10, CPU-only
RAM8GB (default) / 16GB (high_memory)
Timeout1-300 seconds (default: 30)
属性
应用ID
infsh/python-executor
运行环境Python 3.10,仅CPU
内存8GB(默认)/ 16GB(high_memory)
超时时间1-300秒(默认:30)

Input Schema

输入Schema

json
{
  "code": "print('Hello World!')",
  "timeout": 30,
  "capture_output": true,
  "working_dir": null
}
json
{
  "code": "print('Hello World!')",
  "timeout": 30,
  "capture_output": true,
  "working_dir": null
}

Pre-installed Libraries

预装库

Web Scraping & HTTP

网页爬取与HTTP

  • requests
    ,
    httpx
    ,
    aiohttp
    - HTTP clients
  • beautifulsoup4
    ,
    lxml
    - HTML/XML parsing
  • selenium
    ,
    playwright
    - Browser automation
  • scrapy
    - Web scraping framework
  • requests
    ,
    httpx
    ,
    aiohttp
    - HTTP客户端
  • beautifulsoup4
    ,
    lxml
    - HTML/XML解析
  • selenium
    ,
    playwright
    - 浏览器自动化
  • scrapy
    - 网页爬取框架

Data Processing

数据处理

  • numpy
    ,
    pandas
    ,
    scipy
    - Numerical computing
  • matplotlib
    ,
    seaborn
    ,
    plotly
    - Visualization
  • numpy
    ,
    pandas
    ,
    scipy
    - 数值计算
  • matplotlib
    ,
    seaborn
    ,
    plotly
    - 数据可视化

Image Processing

图像处理

  • pillow
    ,
    opencv-python-headless
    - Image manipulation
  • scikit-image
    ,
    imageio
    - Image algorithms
  • pillow
    ,
    opencv-python-headless
    - 图像操作
  • scikit-image
    ,
    imageio
    - 图像算法

Video & Audio

视频与音频

  • moviepy
    - Video editing
  • av
    (PyAV),
    ffmpeg-python
    - Video processing
  • pydub
    - Audio manipulation
  • moviepy
    - 视频编辑
  • av
    (PyAV),
    ffmpeg-python
    - 视频处理
  • pydub
    - 音频操作

3D Processing

3D处理

  • trimesh
    ,
    open3d
    - 3D mesh processing
  • numpy-stl
    ,
    meshio
    ,
    pyvista
    - 3D file formats
  • trimesh
    ,
    open3d
    - 3D网格处理
  • numpy-stl
    ,
    meshio
    ,
    pyvista
    - 3D文件格式

Documents & Graphics

文档与图形

  • svgwrite
    ,
    cairosvg
    - SVG creation
  • reportlab
    ,
    pypdf2
    - PDF generation
  • svgwrite
    ,
    cairosvg
    - SVG创建
  • reportlab
    ,
    pypdf2
    - PDF生成

Examples

示例

Web Scraping

网页爬取

bash
infsh app run infsh/python-executor --input '{
  "code": "import requests\nfrom bs4 import BeautifulSoup\n\nresponse = requests.get(\"https://example.com\")\nsoup = BeautifulSoup(response.content, \"html.parser\")\nprint(soup.find(\"title\").text)"
}'
bash
infsh app run infsh/python-executor --input '{
  "code": "import requests\nfrom bs4 import BeautifulSoup\n\nresponse = requests.get(\"https://example.com\")\nsoup = BeautifulSoup(response.content, \"html.parser\")\nprint(soup.find(\"title\").text)"
}'

Data Analysis with Visualization

带可视化的数据分析

bash
infsh app run infsh/python-executor --input '{
  "code": "import pandas as pd\nimport matplotlib.pyplot as plt\n\ndata = {\"name\": [\"Alice\", \"Bob\"], \"sales\": [100, 150]}\ndf = pd.DataFrame(data)\n\nplt.bar(df[\"name\"], df[\"sales\"])\nplt.savefig(\"outputs/chart.png\")\nprint(\"Chart saved!\")"
}'
bash
infsh app run infsh/python-executor --input '{
  "code": "import pandas as pd\nimport matplotlib.pyplot as plt\n\ndata = {\"name\": [\"Alice\", \"Bob\"], \"sales\": [100, 150]}\ndf = pd.DataFrame(data)\n\nplt.bar(df[\"name\"], df[\"sales\"])\nplt.savefig(\"outputs/chart.png\")\nprint(\"Chart saved!\")"
}'

Image Processing

图像处理

bash
infsh app run infsh/python-executor --input '{
  "code": "from PIL import Image\nimport numpy as np\n\n# Create gradient image\narr = np.linspace(0, 255, 256*256, dtype=np.uint8).reshape(256, 256)\nimg = Image.fromarray(arr, mode=\"L\")\nimg.save(\"outputs/gradient.png\")\nprint(\"Image created!\")"
}'
bash
infsh app run infsh/python-executor --input '{
  "code": "from PIL import Image\nimport numpy as np\n\n# Create gradient image\narr = np.linspace(0, 255, 256*256, dtype=np.uint8).reshape(256, 256)\nimg = Image.fromarray(arr, mode=\"L\")\nimg.save(\"outputs/gradient.png\")\nprint(\"Image created!\")"
}'

Video Creation

视频制作

bash
infsh app run infsh/python-executor --input '{
  "code": "from moviepy.editor import ColorClip, TextClip, CompositeVideoClip\n\nclip = ColorClip(size=(640, 480), color=(0, 100, 200), duration=3)\ntxt = TextClip(\"Hello!\", fontsize=70, color=\"white\").set_position(\"center\").set_duration(3)\nvideo = CompositeVideoClip([clip, txt])\nvideo.write_videofile(\"outputs/hello.mp4\", fps=24)\nprint(\"Video created!\")",
  "timeout": 120
}'
bash
infsh app run infsh/python-executor --input '{
  "code": "from moviepy.editor import ColorClip, TextClip, CompositeVideoClip\n\nclip = ColorClip(size=(640, 480), color=(0, 100, 200), duration=3)\ntxt = TextClip(\"Hello!\", fontsize=70, color=\"white\").set_position(\"center\").set_duration(3)\nvideo = CompositeVideoClip([clip, txt])\nvideo.write_videofile(\"outputs/hello.mp4\", fps=24)\nprint(\"Video created!\")",
  "timeout": 120
}'

3D Model Processing

3D模型处理

bash
infsh app run infsh/python-executor --input '{
  "code": "import trimesh\n\nsphere = trimesh.creation.icosphere(subdivisions=3, radius=1.0)\nsphere.export(\"outputs/sphere.stl\")\nprint(f\"Created sphere with {len(sphere.vertices)} vertices\")"
}'
bash
infsh app run infsh/python-executor --input '{
  "code": "import trimesh\n\nsphere = trimesh.creation.icosphere(subdivisions=3, radius=1.0)\nsphere.export(\"outputs/sphere.stl\")\nprint(f\"Created sphere with {len(sphere.vertices)} vertices\")"
}'

API Calls

API调用

bash
infsh app run infsh/python-executor --input '{
  "code": "import requests\nimport json\n\nresponse = requests.get(\"https://api.github.com/users/octocat\")\ndata = response.json()\nprint(json.dumps(data, indent=2))"
}'
bash
infsh app run infsh/python-executor --input '{
  "code": "import requests\nimport json\n\nresponse = requests.get(\"https://api.github.com/users/octocat\")\ndata = response.json()\nprint(json.dumps(data, indent=2))"
}'

File Output

文件输出

Files saved to
outputs/
are automatically returned:
python
undefined
保存到
outputs/
目录的文件会自动返回:
python
undefined

These files will be in the response

These files will be in the response

plt.savefig('outputs/chart.png') df.to_csv('outputs/data.csv') video.write_videofile('outputs/video.mp4') mesh.export('outputs/model.stl')
undefined
plt.savefig('outputs/chart.png') df.to_csv('outputs/data.csv') video.write_videofile('outputs/video.mp4') mesh.export('outputs/model.stl')
undefined

Variants

变体

bash
undefined
bash
undefined

Default (8GB RAM)

Default (8GB RAM)

infsh app run infsh/python-executor --input input.json
infsh app run infsh/python-executor --input input.json

High memory (16GB RAM) for large datasets

High memory (16GB RAM) for large datasets

infsh app run infsh/python-executor@high_memory --input input.json
undefined
infsh app run infsh/python-executor@high_memory --input input.json
undefined

Use Cases

适用场景

  • Web scraping - Extract data from websites
  • Data analysis - Process and visualize datasets
  • Image manipulation - Resize, crop, composite images
  • Video creation - Generate videos with text overlays
  • 3D processing - Load, transform, export 3D models
  • API integration - Call external APIs
  • PDF generation - Create reports and documents
  • Automation - Run any Python script
  • 网页爬取 - 从网站提取数据
  • 数据分析 - 处理并可视化数据集
  • 图像操作 - 调整大小、裁剪、合成图像
  • 视频制作 - 生成带文本叠加层的视频
  • 3D处理 - 加载、转换、导出3D模型
  • API集成 - 调用外部API
  • PDF生成 - 创建报告和文档
  • 自动化 - 运行任意Python脚本

Important Notes

重要说明

  • CPU-only - No GPU/ML libraries (use dedicated AI apps for that)
  • Safe execution - Runs in isolated subprocess
  • Non-interactive - Use
    plt.savefig()
    not
    plt.show()
  • File detection - Output files are auto-detected and returned
  • 仅支持CPU - 无GPU/ML库(此类需求请使用专用AI应用)
  • 安全执行 - 在独立子进程中运行
  • 非交互式 - 使用
    plt.savefig()
    而非
    plt.show()
  • 文件检测 - 输出文件会被自动检测并返回

Related Skills

相关技能

bash
undefined
bash
undefined

AI image generation (for ML-based images)

AI image generation (for ML-based images)

npx skills add inferencesh/skills@ai-image-generation
npx skills add inferencesh/skills@ai-image-generation

AI video generation (for ML-based videos)

AI video generation (for ML-based videos)

npx skills add inferencesh/skills@ai-video-generation
npx skills add inferencesh/skills@ai-video-generation

LLM models (for text generation)

LLM models (for text generation)

npx skills add inferencesh/skills@llm-models
undefined
npx skills add inferencesh/skills@llm-models
undefined

Documentation

文档