ClaudeMap

Claude Agent SDK (Python)

Python edition of the official Claude Agent SDK.

SDKs & Toolingofficialsdkpythonanthropic

Python edition of the official Claude Agent SDK. Embeds the Claude Code agent loop (tools, context management, hooks) in Python programs so you can build production agents without reimplementing the runtime.

What it does

  • query() async-generator API — iterate the message stream (AssistantTextMessage / ToolUseBlock / ToolResultBlock / ResultMessage)
  • ClaudeAgentOptions: allowed_tools / permission_mode / cwd / model / hooks / mcp_servers / max_turns / max_budget_usd / fallback_model
  • MCP server wiring (stdio + HTTP/SSE) merged with project-level .mcp.json
  • Hooks system — PreToolUse / PostToolUse / Stop / SubagentStop; structured JSON audit logging via async iteration
  • Driven by the bundled Claude Code CLI — inherits all built-in tools, context management, and permission model

When to use it

Best for Python production agents — CI pipelines, triage bots, research assistants, multi-agent research with asyncio.gather(*queries, return_exceptions=True). Pairs with FastAPI for serving, any Python queue for background dispatch, and existing logging stacks for audit. The Python companion to the TypeScript SDK.

Getting started

pip install claude-agent-sdk
# or
uv add claude-agent-sdk

Requires Python 3.10+, the Claude Code CLI on PATH, and ANTHROPIC_API_KEY set. The SDK runs the CLI under the hood.

Things to know

Pin to a major version — the SDK's Pydantic models evolve between minor releases. Always set max_turns and max_budget_usd in production. For multi-agent fan-out, prefer asyncio.gather(*queries, return_exceptions=True) — using asyncio.as_completed directly on async generators will raise TypeError.

Repository

anthropics/claude-agent-sdk-python

Charted

Related on the map

  • Harness Bridge

    SDK / Tool

    A local launcher that points Claude Code and seven other coding harnesses at any OpenAI-, Anthropic- or Responses-compatible endpoint — without editing a single config file.

    • launcher
    • local-models
    • cli
    • menu-bar
  • Claude for Siri

    SDK / Tool

    Answers macOS Spotlight and Siri prompts with your signed-in Claude Code account — an experimental macOS 27 model-delegation provider.

    • macos
    • siri
    • spotlight
    • model-delegation
  • Extract your own local chat history from ten AI coding assistants into one normalized JSONL — for fine-tuning, analytics, or backing up years of conversations. Standard library only.

    • cli
    • data-export
    • jsonl
    • backup