A Python SDK for interacting with Claude Code, Anthropic's AI-powered coding assistant.
This package is not available on PyPI and must be installed directly from git:
pip install git+https://github.com/mayflower/claude-code-sdk-python.git
Or for development:
git clone https://github.com/mayflower/claude-code-sdk-python.git
cd claude-code-sdk-python
pip install -e .
- Python 3.8 or higher
- Claude Code CLI installed (
npm install -g @anthropic-ai/claude-code
)
from claude_code import ClaudeCode, AuthType
# Initialize with Anthropic API key
claude = ClaudeCode(
auth_type=AuthType.ANTHROPIC_API,
api_key="your-api-key"
)
# Run a single prompt
result = claude.run_prompt("Explain how this project works")
print(result)
# Stream results
for chunk in claude.stream_prompt("Create a function to parse JSON"):
print(chunk, end="")
from claude_code import ClaudeCode, AuthType
claude = ClaudeCode(
auth_type=AuthType.ANTHROPIC_API,
api_key="your-api-key"
)
# Start a conversation
conversation = claude.start_conversation()
# Send multiple prompts in the same conversation
response1 = conversation.send("Create a Python class for a blog post")
print(response1)
response2 = conversation.send("Add methods for comments")
print(response2)
from claude_code import ClaudeCode, AuthType
# Initialize with AWS Bedrock
claude = ClaudeCode(
auth_type=AuthType.AWS_BEDROCK,
model="anthropic.claude-3-7-sonnet-20250219-v1:0",
region="us-west-2"
)
# Now use it as normal
result = claude.run_prompt("Analyze this code")
from claude_code import ClaudeCode, AuthType
# Initialize with Google Vertex AI
claude = ClaudeCode(
auth_type=AuthType.GOOGLE_VERTEX,
model="claude-3-7-sonnet@20250219",
project_id="your-project-id",
region="us-central1"
)
# Now use it as normal
result = claude.run_prompt("Refactor this function")
from claude_code import ClaudeCode, AuthType
claude = ClaudeCode(
auth_type=AuthType.ANTHROPIC_API,
api_key="your-api-key"
)
# Configure allowed tools
claude.configure(
allowed_tools=["Bash(git:*)", "View", "Glob", "Grep"],
max_turns=5
)
# Run with tool access
result = claude.run_prompt("Find all Python files in this project")
MIT
Johann-Peter Hartmann (johann-peter.hartmann@mayflower.de)