
Claude Agent SDK (Python)
https://github.com/anthropics/claude-agent-sdk-python- Category
- Developer Tools
- Rank
- No. 245Tools index
- Pricing
- Open Source
- Type
- TOOL
- Builder
- anthropics
- GitHub
- 8.1k stars
- Latest release
- v0.2.152
- Date
About
Anthropic's official Python SDK for building Claude-powered agents — the same agent loop that powers Claude Code, exposed for your own apps.
What it does
An asynchronous Python library that streams agent messages through a bundled command-line runtime. It supports independent jobs, stateful conversations, custom tools, lifecycle hooks, permissions, interrupts, session management, and both in-process and external MCP servers.
Why it's ranked here
The package offers unusually deep control over agent behavior while keeping simple jobs concise. Typed messages, explicit permissions, deterministic hooks, custom transports, and interactive sessions make it credible for real automation. Its dependence on a bundled command-line subprocess adds operational weight and coupling.
What's good
Custom Python tools can run as in-process MCP servers, avoiding separate server processes and IPC. Hooks can approve, deny, stop, or add context around tool activity. The API distinguishes stateless streaming from stateful interaction, exposes structured message and error types, and supports asyncio and Trio through AnyIO.
Tradeoffs
The default path still launches and communicates with a bundled Claude Code executable. Interactive clients must remain within the asynchronous runtime context where they connected. Tool allowlists grant automatic approval rather than limiting availability, so blocking requires separate deny rules. End-to-end tests need an API key and make real API calls.
How to use it well
Choose it for Python automation, chat interfaces, coding workflows, or long-running sessions that need tools, permissions, hooks, and structured streaming. Use the simpler query interface for independent batch work and the interactive client for follow-ups or interrupts. It does not provide a standalone model runtime or remove the need to design a careful tool security policy.
Technical notes+
src/claude_agent_sdk/query.py routes one-shot and unidirectional streaming work through InternalClient.process_query(). src/claude_agent_sdk/client.py builds stateful sessions over SubprocessCLITransport, initializes the control protocol, converts hooks, and accepts a custom Transport. src/claude_agent_sdk/__init__.py exports the public surface and implements typed in-process MCP tools through tool() and create_sdk_mcp_server(). src/claude_agent_sdk/types.py defines permission modes, hooks, messages, agents, session types, and callback contracts. src/claude_agent_sdk/_internal/transport/__init__.py marks the transport abstraction as unstable. pyproject.toml uses Hatchling, requires Python 3.10 or newer, declares strict mypy settings, and configures pytest under tests. e2e-tests/conftest.py requires ANTHROPIC_API_KEY and pins real-call tests to asyncio.
Observed
- Primary language
- Python
- Install surface
- PyPI package installed with pip as claude-agent-sdk
- Python support
- Python 3.10 or newer; classifiers include Python 3.10 through 3.13
- Interfaces
- Async Python library, bundled Claude Code CLI transport, custom transport interface, and MCP server integration
- Platform packaging
- Release workflow builds platform-specific wheels for macOS, Linux, and Windows, plus a source distribution
- License metadata
- Package metadata declares MIT; the README also states SDK use is governed by Anthropic Commercial Terms except separately licensed components
- Test structure
- The repository includes unit-test configuration and a separate e2e-tests directory for real API calls
Read from README.md, pyproject.toml, src/claude_agent_sdk/query.py, src/claude_agent_sdk/types.py, src/claude_agent_sdk/client.py, src/claude_agent_sdk/_errors.py, src/claude_agent_sdk/__init__.py, src/claude_agent_sdk/_version.py, src/claude_agent_sdk/_cli_version.py, src/claude_agent_sdk/testing/__init__.py, src/claude_agent_sdk/_internal/__init__.py, src/claude_agent_sdk/_internal/transport/__init__.py, e2e-tests/conftest.py, scripts/build_wheel.py, e2e-tests/test_hooks.py.
What it can do
Build Claude-powered conversational agents
Python code and configuration → Interactive AI agent application
Generate and execute code automatically
Natural language programming requests → Working code solutions
Process multi-turn conversations with context
User messages and conversation history → Contextually aware responses
Integrate Claude's reasoning into custom applications
Application logic and user queries → AI-enhanced application responses
Handle tool usage and function calling
Tool definitions and user requests → Executed tool results and responses
Manage agent state and memory
Conversation data and state information → Persistent agent context and memory
Tags
Tech Stack
Comments (0)
No comments yet
Editorially curated, with community endorsements as a secondary signal. Corrections welcome.