anthropic-claude-development by mindrally/skills
npx skills add https://github.com/mindrally/skills --skill anthropic-claude-development您是 Anthropic Claude API 开发方面的专家,包括 Messages API、工具使用、提示工程以及使用 Claude 模型构建生产就绪的应用程序。
import os
from anthropic import Anthropic
# 始终使用环境变量存储 API 密钥
client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
.env 文件中,切勿提交到版本控制python-dotenvfrom anthropic import Anthropic
client = Anthropic()
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system="You are a helpful assistant.",
messages=[
{"role": "user", "content": "Hello, Claude!"}
]
)
print(message.content[0].text)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
with client.messages.stream(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a story"}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
claude-opus-4-20250514 进行复杂推理和分析claude-sonnet-4-20250514 以获得平衡的性能和成本claude-3-5-haiku-20241022 以获得快速、高效的响应tools = [
{
"name": "get_weather",
"description": "获取指定地点的当前天气",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市和州,例如:San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "温度单位"
}
},
"required": ["location"]
}
}
]
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=tools,
messages=[{"role": "user", "content": "What's the weather in London?"}]
)
import json
def process_tool_use(response, messages, tools):
# 检查 Claude 是否想要使用工具
if response.stop_reason == "tool_use":
tool_use_block = next(
block for block in response.content
if block.type == "tool_use"
)
tool_name = tool_use_block.name
tool_input = tool_use_block.input
# 执行工具
tool_result = execute_tool(tool_name, tool_input)
# 继续对话
messages.append({"role": "assistant", "content": response.content})
messages.append({
"role": "user",
"content": [{
"type": "tool_result",
"tool_use_id": tool_use_block.id,
"content": json.dumps(tool_result)
}]
})
# 获取最终响应
return client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=tools,
messages=messages
)
return response
import base64
# 从 URL
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "url",
"url": "https://example.com/image.jpg"
}
},
{
"type": "text",
"text": "Describe this image in detail."
}
]
}]
)
# 从 base64
with open("image.png", "rb") as f:
image_data = base64.standard_b64encode(f.read()).decode("utf-8")
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": image_data
}
},
{
"type": "text",
"text": "What do you see?"
}
]
}]
)
清晰具体地说明助手的角色
包含相关上下文和约束条件
需要时指定输出格式
使用 XML 标签来结构化指令
system_prompt = """You are a technical documentation writer.
<guidelines> - Write clear, concise documentation - Use proper markdown formatting - Include code examples where appropriate - Follow the Google developer documentation style guide </guidelines><output_format> Always structure your response with:
from anthropic import RateLimitError, APIError
import time
def call_with_retry(func, max_retries=3, base_delay=1):
for attempt in range(max_retries):
try:
return func()
except RateLimitError:
delay = base_delay * (2 ** attempt)
print(f"Rate limited. Retrying in {delay}s...")
time.sleep(delay)
except APIError as e:
if attempt == max_retries - 1:
raise
time.sleep(base_delay)
raise Exception("Max retries exceeded")
RateLimitError: 实现指数退避APIError: 检查 API 状态,使用退避策略重试AuthenticationError: 验证 API 密钥BadRequestError: 验证输入参数# 为频繁使用的上下文启用缓存
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system=[{
"type": "text",
"text": "Large context that should be cached...",
"cache_control": {"type": "ephemeral"}
}],
messages=[{"role": "user", "content": "Question about the context"}]
)
# 为非时间敏感请求创建批次
batch = client.messages.batches.create(
requests=[
{
"custom_id": "request-1",
"params": {
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Question 1"}]
}
},
{
"custom_id": "request-2",
"params": {
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Question 2"}]
}
}
]
)
max_tokens 限制每周安装数
92
代码仓库
GitHub 星标数
42
首次出现
Jan 25, 2026
安全审计
安装于
opencode75
claude-code75
gemini-cli75
codex71
cursor70
github-copilot67
You are an expert in Anthropic Claude API development, including the Messages API, tool use, prompt engineering, and building production-ready applications with Claude models.
import os
from anthropic import Anthropic
# Always use environment variables for API keys
client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
.env files, never commit thempython-dotenv for local developmentfrom anthropic import Anthropic
client = Anthropic()
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system="You are a helpful assistant.",
messages=[
{"role": "user", "content": "Hello, Claude!"}
]
)
print(message.content[0].text)
with client.messages.stream(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a story"}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
claude-opus-4-20250514 for complex reasoning and analysisclaude-sonnet-4-20250514 for balanced performance and costclaude-3-5-haiku-20241022 for fast, efficient responsestools = [
{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g., San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The unit of temperature"
}
},
"required": ["location"]
}
}
]
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=tools,
messages=[{"role": "user", "content": "What's the weather in London?"}]
)
import json
def process_tool_use(response, messages, tools):
# Check if Claude wants to use a tool
if response.stop_reason == "tool_use":
tool_use_block = next(
block for block in response.content
if block.type == "tool_use"
)
tool_name = tool_use_block.name
tool_input = tool_use_block.input
# Execute the tool
tool_result = execute_tool(tool_name, tool_input)
# Continue the conversation
messages.append({"role": "assistant", "content": response.content})
messages.append({
"role": "user",
"content": [{
"type": "tool_result",
"tool_use_id": tool_use_block.id,
"content": json.dumps(tool_result)
}]
})
# Get final response
return client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=tools,
messages=messages
)
return response
import base64
# From URL
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "url",
"url": "https://example.com/image.jpg"
}
},
{
"type": "text",
"text": "Describe this image in detail."
}
]
}]
)
# From base64
with open("image.png", "rb") as f:
image_data = base64.standard_b64encode(f.read()).decode("utf-8")
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": image_data
}
},
{
"type": "text",
"text": "What do you see?"
}
]
}]
)
Be clear and specific about the assistant's role
Include relevant context and constraints
Specify output format when needed
Use XML tags for structured instructions
system_prompt = """You are a technical documentation writer.
<guidelines> - Write clear, concise documentation - Use proper markdown formatting - Include code examples where appropriate - Follow the Google developer documentation style guide </guidelines><output_format> Always structure your response with:
from anthropic import RateLimitError, APIError
import time
def call_with_retry(func, max_retries=3, base_delay=1):
for attempt in range(max_retries):
try:
return func()
except RateLimitError:
delay = base_delay * (2 ** attempt)
print(f"Rate limited. Retrying in {delay}s...")
time.sleep(delay)
except APIError as e:
if attempt == max_retries - 1:
raise
time.sleep(base_delay)
raise Exception("Max retries exceeded")
RateLimitError: Implement exponential backoffAPIError: Check API status, retry with backoffAuthenticationError: Verify API keyBadRequestError: Validate input parameters# Enable caching for frequently used context
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system=[{
"type": "text",
"text": "Large context that should be cached...",
"cache_control": {"type": "ephemeral"}
}],
messages=[{"role": "user", "content": "Question about the context"}]
)
# Create a batch for non-time-sensitive requests
batch = client.messages.batches.create(
requests=[
{
"custom_id": "request-1",
"params": {
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Question 1"}]
}
},
{
"custom_id": "request-2",
"params": {
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Question 2"}]
}
}
]
)
max_tokens limitsWeekly Installs
92
Repository
GitHub Stars
42
First Seen
Jan 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode75
claude-code75
gemini-cli75
codex71
cursor70
github-copilot67
超能力技能使用指南:AI助手技能调用优先级与工作流程详解
50,500 周安装
项目文件夹结构蓝图生成器 - 自动生成多技术栈项目结构文档,提升代码组织一致性
7,800 周安装
Fluent UI Blazor 使用指南:Microsoft.FluentUI.AspNetCore.Components 4 版本完整教程
7,800 周安装
finalize-agent-prompt:AI智能体提示词优化工具,提升GitHub Copilot提示词质量与效率
7,800 周安装
Debian Linux 问题排查指南:使用 systemctl、journalctl、apt 诊断与修复系统故障
7,800 周安装
AI测试规划与质量保障提示:基于ISTQB与ISO 25010的全面测试策略生成
7,900 周安装
Epic架构规范提示:AI辅助软件架构设计,生成领域驱动技术方案
7,800 周安装