网淘吧来吧,欢迎您!

返回首页 微信
微信
手机版
手机版

Python Executor

2026-03-27 新闻来源:网淘吧 围观:23
电脑广告
手机广告

Python 代码执行器

在安全、沙盒化的环境中执行 Python 代码,预装 100 多个库。

Python Code Executor

快速开始

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,seabornplotly- 可视化

图像处理

  • pillowopencv-python-headless- 图像操作
  • scikit-imageimageio- 图像算法

视频与音频

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

三维处理

  • trimeshopen3d- 三维网格处理
  • 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

相关文章

您是本站第289869名访客 今日有232篇新文章/评论