Python Executor
2026-03-27
新闻来源:网淘吧
围观:25
电脑广告
手机广告
Python 代码执行器
在安全、沙盒化的环境中执行 Python 代码,预装 100 多个库。

快速开始
curl -fsSL https://cli.inference.sh | sh && infsh login
# Run Python code
infsh app run infsh/python-executor --input '{
"code": "import pandas as pd\nprint(pd.__version__)"
}'
安装说明:安装脚本仅会检测您的操作系统/架构,从dist.inference.sh
下载匹配的二进制文件,并验证其 SHA-256 校验和。无需提升权限或后台进程。提供手动安装和验证方式。应用详情
属性
| 值 | 应用 ID |
|---|---|
| infsh/python-executor | 环境 |
| Python 3.10,仅 CPU | 内存 |
| 8GB(默认)/ 16GB(高内存) | 超时 |
| 1-300 秒(默认:30) | 输入模式 |
Input Schema
{
"code": "print('Hello World!')",
"timeout": 30,
"capture_output": true,
"working_dir": null
}
预装库
网络爬虫与HTTP
requests,httpx,aiohttp- HTTP客户端beautifulsoup4,lxml- HTML/XML解析selenium,playwright- 浏览器自动化scrapy- 网络爬虫框架
数据处理
numpy,pandas,scipy- 数值计算matplotlib,seaborn,plotly- 可视化
图像处理
pillow,opencv-python-headless- 图像操作scikit-image,imageio- 图像算法
视频与音频
moviepy- 视频编辑av(PyAV),ffmpeg-python- 视频处理pydub- 音频操作
三维处理
trimesh,open3d- 三维网格处理numpy-stl,meshio,pyvista- 3D文件格式
文档与图形
svgwrite,cairosvg- SVG创建reportlab,pypdf2- PDF生成
示例
网络爬虫
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)"
}'
数据分析与可视化
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!\")"
}'
图像处理
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!\")"
}'
视频创作
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模型处理
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调用
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))"
}'
文件输出
保存至outputs/目录下的文件会自动返回:
# 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')
变体
# Default (8GB RAM)
infsh app run infsh/python-executor --input input.json
# High memory (16GB RAM) for large datasets
infsh app run infsh/python-executor@high_memory --input input.json
使用案例
- 网络爬虫- 从网站提取数据
- 数据分析- 处理和可视化数据集
- 图像处理- 调整尺寸、裁剪、合成图像
- 视频创作- 生成带文字叠加的视频
- 3D处理- 加载、转换、导出3D模型
- API集成- 调用外部API
- PDF生成- 创建报告和文档
- 自动化- 运行任何Python脚本
重要说明
- 仅限CPU- 无GPU/机器学习库(请使用专用AI应用处理此类任务)
- 安全执行- 在隔离子进程中运行
- 非交互式- 使用
plt.savefig()而非plt.show() - 文件检测- 输出文件自动检测并返回
相关技能
# AI image generation (for ML-based images)
npx skills add inference-sh/skills@ai-image-generation
# AI video generation (for ML-based videos)
npx skills add inference-sh/skills@ai-video-generation
# LLM models (for text generation)
npx skills add inference-sh/skills@llm-models
文档
文章底部电脑广告
手机广告位-内容正文底部
上一篇:Stock Monitor
下一篇:Elevenlabs Tts


微信扫一扫,打赏作者吧~