据 AlphaMoat 统计,截至 2026-09,Python Sdk 累计下载 3,224 次、获 1 个星标,在全部 5,078 个 AI 技能中排名第 3,530 位,在「AI 智能体」分类(969 个)中排名第 721 位。
| 平台 | 累计安装 | 累计下载 | 星标 | 评论 |
|---|---|---|---|---|
| ClawHub ↗ | 76 | 2,559 | - | - |
| SkillHub ↗ | 263 | 3,224 | 1 | — |
各平台的计数口径不同,统计时间不一致。
快速开始:pip install inferencesh(异步支持装 inferencesh[async]),要求 Python 3.8+;用 inference(api_key=...) 初始化,推荐从环境变量 INFERENCE_API_KEY 读取。运行应用:client.run 同步执行并返回 status/output;wait=False 即发即弃后用 get_task 查询;stream=True 流式获取进度与日志。Run 参数含 app、input、setup、infra(cloud/private)、session、session_timeout(空闲超时 1-3600 秒)。文件处理:输入传本地路径自动上传,或用 upload_file + UploadFileOptions 手动上传。Sessions 让 worker 在多次调用间保温(session="new" 开启,回传 session_id 续用)。Agent SDK:模板 agent(workspace 预建,支持多轮对话与 reset)与 ad-hoc agent(core_app + system_prompt + tools,核心应用如 infsh/claude-sonnet-4@latest、infsh/gpt-4o@latest)。Tool Builder API 五类工具:client 工具(tool())、app 工具(app_tool())、agent 工具(agent_tool() 委派子 agent)、webhook 工具(webhook_tool() 调外部 API)、internal 工具(plan/memory/web_search/code_execution/image_generation 内建能力),参数类型含 string/number/integer/boolean/enum_of/array/obj/optional,可 require_approval() 人工审批。另支持 Skills 复用上下文、async_inference 异步、RequirementsNotMetException 错误处理与人工审批工作流。
资料发布于 2026-10-27
以下是根据技能文档生成的示例,不代表实际运行结果。
2026-09 起统计方法调整:同名技能按作者分别统计,并覆盖全部技能。图中虚线为调整前的月份,与之后的数据不直接比较,也不计算跨越调整的增长。
| 月份 | 累计下载 | 环比 | 星标 |
|---|---|---|---|
| 2026-09 | 3,224 | — | 1 |
| 2026-08 | 2,610 | +11.8% | 1 |
| 2026-07 | 2,335 | +13.3% | 1 |
| 2026-06 | 2,060 | +9.4% | 1 |
| 2026-05 | 1,883 | — | 1 |
| 2026-03 | 1,436 | — | - |
以下是作者发布的原始文件,按纯文本显示,本站未做修改或审核;其中的链接不可点击,命令请核实后再运行。抓取于 2026-10-23。
--- name: python-sdk description: "Python SDK for inference.sh - run AI apps, build agents, and integrate with 150+ models. Package: inferencesh (pip install inferencesh). Supports sync/async, streaming, file uploads. Build agents with template or ad-hoc patterns, tool builder API, skills, and human approval. Use for: Python integration, AI apps, agent development, RAG pipelines, automation. Triggers: python sdk, inferencesh, pip install, python api, python client, async inference, python agent, tool builder python, programmatic ai, python integration, sdk python" allowed-tools: Bash(pip install inferencesh), Bash(python *) --- # Python SDK Build AI applications with the [inference.sh](https://inference.sh) Python SDK.

## Quick Start
```bash
pip install inferencesh
```
```python
from inferencesh import inference
client = inference(api_key="inf_your_key")
# Run an AI app
result = client.run({
"app": "infsh/flux-schnell",
"input": {"prompt": "A sunset over mountains"}
})
print(result["output"])
```
## Installation
```bash
# Standard installation
pip install inferencesh
# With async support
pip install inferencesh[async]
```
**Requirements:** Python 3.8+
## Authentication
```python
import os
from inferencesh import inference
# Direct API key
client = inference(api_key="inf_your_key")
# From environment variable (recommended)
client = inference(api_key=os.environ["INFERENCE_API_KEY"])
```
Get your API key: Settings → API Keys → Create API Key
## Running Apps
### Basic Execution
```python
result = client.run({
"app": "infsh/flux-schnell",
"input": {"prompt": "A cat astronaut"}
})
print(result["status"]) # "completed"
print(result["output"]) # Output data
```
### Fire and Forget
```python
task = client.run({
"app": "google/veo-3-1-fast",
"input": {"prompt": "Drone flying over mountains"}
}, wait=False)
print(f"Task ID: {task['id']}")
# Check later with client.get_task(task['id'])
```
### Streaming Progress
```python
for update in client.run({
"app": "google/veo-3-1-fast",
"input": {"prompt": "Ocean waves at sunset"}
}, stream=True):
print(f"Status: {update['status']}")
if update.get("logs"):
print(update["logs"][-1])
```
### Run Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `app` | string | App ID (namespace/name@version) |
| `input` | dict | Input matching app schema |
| `setup` | dict | Hidden setup configuration |
| `infra` | string | 'cloud' or 'private' |
| `session` | string | Session ID for stateful execution |
| `session_timeout` | int | Idle timeout (1-3600 seconds) |
## File Handling
### Automatic Upload
```python
result = client.run({
"app": "image-processor",
"input": {
"image": "/path/to/image.png" # Auto-uploaded
}
})
```
### Manual Upload
```python
from inferencesh import UploadFileOptions
# Basic upload
file = client.upload_file("/path/to/image.png")
# With options
file = client.upload_file(
"/path/to/image.png",
UploadFileOptions(
filename="custom_name.png",
content_type="image/png",
public=True
)
)
result = client.run({
"app": "image-processor",
"input": {"image": file["uri"]}
})
```
## Sessions (Stateful Execution)
Keep workers warm across multiple calls:
```python
# Start new session
result = client.run({
"app": "my-app",
"input": {"action": "init"},
"session": "new",
"session_timeout": 300 # 5 minutes
})
session_id = result["session_id"]
# Continue in same session
result = client.run({
"app": "my-app",
"input": {"action": "process"},
"session": session_id
})
```
## Agent SDK
### Template Agents
Use pre-built agents from your workspace:
```python
agent = client.agent("my-team/support-agent@latest")
# Send message
response = agent.send_message("Hello!")
print(response.text)
# Multi-turn conversation
response = agent.send_message("Tell me more")
# Reset conversation
agent.reset()
# Get chat history
chat = agent.get_chat()
```
### Ad-hoc Agents
Create custom agents programmatically:
```python
from inferencesh import tool, string, number, app_tool
# Define tools
calculator = (
tool("calculate")
.describe("Perform a calculation")
.param("expression", string("Math expression"))
.build()
)
image_gen = (
app_tool("generate_image", "infsh/flux-schnell@latest")
.describe("Generate an image")
.param("prompt", string("Image description"))
.build()
)
# Create agent
agent = client.agent({
"core_app": {"ref": "infsh/claude-sonnet-4@latest"},
"system_prompt": "You are a helpful assistant.",
"tools": [calculator, image_gen],
"temperature": 0.7,
"max_tokens": 4096
})
response = agent.send_message("What is 25 * 4?")
```
### Available Core Apps
| Model | App Reference |
|-------|---------------|
| Claude Sonnet 4 | `infsh/claude-sonnet-4@latest` |
| Claude 3.5 Haiku | `infsh/claude-haiku-35@latest` |
| GPT-4o | `infsh/gpt-4o@latest` |
| GPT-4o Mini | `infsh/gpt-4o-mini@latest` |
## Tool Builder API
### Parameter Types
```python
from inferencesh import (
string, number, integer, boolean,
enum_of, array, obj, optional
)
name = string("User's name")
age = integer("Age in years")
score = number("Score 0-1")
active = boolean("Is active")
priority = enum_of(["low", "medium", "high"], "Priority")
tags = array(string("Tag"), "List of tags")
address = obj({
"street": string("Street"),
"city": string("City"),
"zip": optional(string("ZIP"))
}, "Address")
```
### Client Tools (Run in Your Code)
```python
greet = (
tool("greet")
.display("Greet User")
.describe("Greets a user by name")
.param("name", string("Name to greet"))
.require_approval()
.build()
)
```
### App Tools (Call AI Apps)
```python
generate = (
app_tool("generate_image", "infsh/flux-schnell@latest")
.describe("Generate an image from text")
.param("prompt", string("Image description"))
.setup({"model": "schnell"})
.input({"steps": 20})
.require_approval()
.build()
)
```
### Agent Tools (Delegate to Sub-agents)
```python
from inferencesh import agent_tool
researcher = (
agent_tool("research", "my-org/researcher@v1")
.describe("Research a topic")
.param("topic", string("Topic to research"))
.build()
)
```
### Webhook Tools (Call External APIs)
```python
from inferencesh import webhook_tool
notify = (
webhook_tool("slack", "https://hooks.slack.com/...")
.describe("Send Slack notification")
.secret("SLACK_SECRET")
.param("channel", string("Channel"))
.param("message", string("Message"))
.build()
)
```
### Internal Tools (Built-in Capabilities)
```python
from inferencesh import internal_tools
config = (
internal_tools()
.plan()
.memory()
.web_search(True)
.code_execution(True)
.image_generation({
"enabled": True,
"app_ref": "infsh/flux@latest"
})
.build()
)
agent = client.agent({
"core_app": {"ref": "infsh/claude-sonnet-4@latest"},
"internal_tools": config
})
```
## Streaming Agent Responses
```python
def handle_message(msg):
if msg.get("content"):
print(msg["content"], end="", flush=True)
def handle_tool(call):
print(f"\n[Tool: {call.name}]")
result = execute_tool(call.name, call.args)
agent.submit_tool_result(call.id, result)
response = agent.send_message(
"Explain quantum computing",
on_message=handle_message,
on_tool_call=handle_tool
)
```
## File Attachments
```python
# From file path
with open("image.png", "rb") as f:
response = agent.send_message(
"What's in this image?",
files=[f.read()]
)
# From base64
response = agent.send_message(
"Analyze this",
files=["data:image/png;base64,iVBORw0KGgo..."]
)
```
## Skills (Reusable Context)
```python
agent = client.agent({
"core_app": {"ref": "infsh/claude-sonnet-4@latest"},
"skills": [
{
"name": "code-review",
"description": "Code review guidelines",
"content": "# Code Review\n\n1. Check security\n2. Check performance..."
},
{
"name": "api-docs",
"description": "API documentation",
"url": "https://example.com/skills/api-docs.md"
}
]
})
```
## Async Support
```python
from inferencesh import async_inference
import asyncio
async def main():
client = async_inference(api_key="inf_...")
# Async app execution
result = await client.run({
"app": "infsh/flux-schnell",
"input": {"prompt": "A galaxy"}
})
# Async agent
agent = client.agent("my-org/assistant@latest")
response = await agent.send_message("Hello!")
# Async streaming
async for msg in agent.stream_messages():
print(msg)
asyncio.run(main())
```
## Error Handling
```python
from inferencesh import RequirementsNotMetException
try:
result = client.run({"app": "my-app", "input": {...}})
except RequirementsNotMetException as e:
print(f"Missing requirements:")
for err in e.errors:
print(f" - {err['type']}: {err['key']}")
except RuntimeError as e:
print(f"Error: {e}")
```
## Human Approval Workflows
```python
def handle_tool(call):
if call.requires_approval:
# Show to user, get confirmation
approved = prompt_user(f"Allow {call.name}?")
if approved:
result = execute_tool(call.name, call.args)
agent.submit_tool_result(call.id, result)
else:
agent.submit_tool_result(call.id, {"error": "Denied by user"})
response = agent.send_message(
"Delete all temp files",
on_tool_call=handle_tool
)
```
## Reference Files
- [Agent Patterns](references/agent-patterns.md) - Multi-agent, RAG, human-in-the-loop patterns
- [Tool Builder](references/tool-builder.md) - Complete tool builder API reference
- [Streaming](references/streaming.md) - Real-time progress updates and SSE handling
- [File Handling](references/files.md) - Upload, download, and manage files
- [Sessions](references/sessions.md) - Stateful execution with warm workers
- [Async Patterns](references/async-patterns.md) - Parallel processing and async/await
## Related Skills
```bash
# JavaScript SDK
npx skills add inference-sh/skills@javascript-sdk
# Full platform skill (all 150+ apps via CLI)
npx skills add inference-sh/skills@inference-sh
# LLM models
npx skills add inference-sh/skills@llm-models
# Image generation
npx skills add inference-sh/skills@ai-image-generation
```
## Documentation
- [Python SDK Reference](https://inference.sh/docs/api/sdk-python) - Full API documentation
- [Agent SDK Overview](https://inference.sh/docs/api/agent-sdk) - Building agents
- [Tool Builder Reference](https://inference.sh/docs/api/agent-tools) - Creating tools
- [Authentication](https://inference.sh/docs/api/authentication) - API key setup
- [Streaming](https://inference.sh/docs/api/sdk/streaming) - Real-time updates
- [File Uploads](https://inference.sh/docs/api/sdk/files) - File handling
把开发过程中的经验、错误与纠正记录为 Markdown 文件,供后续复用并晋升为工作区记忆。
用自然语言描述需求,在本地与远程技能市场里找技能并给出推荐的技能。
给 AI agent 用的浏览器自动化命令行技能。
把用户纠正与自我复盘沉淀成分层记忆、并按使用情况升降级的技能。
在安装第三方技能之前,按清单审查来源、权限与危险模式的技能。
把 agent 的记忆与跨技能状态存成带类型和约束的知识图谱的技能。
一份为 AI 代理规划主动跟进、工作记忆与复盘流程的工作区配置指南。
指导如何创建与更新有效 Claude 技能的写作指南。
data-visualization 为图表选择、配色、坐标轴和数据叙事提供设计指南。
在托管沙箱里执行 Python 代码的技能。
通过 inference.sh 命令行工具生成 AI 图像的多模型技能。
用 inference.sh 组合批处理、顺序和定时 AI 工作流。
数据月份:2026-09 · 下载/星标/安装数聚合自公开技能注册库(ClawHub、SkillHub),按月更新。口径说明见数据方法。