| Name | claude-code-sdk JSON |
| Version |
0.0.21
JSON |
| download |
| home_page | None |
| Summary | Python SDK for Claude Code |
| upload_time | 2025-09-05 20:39:47 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.10 |
| license | MIT |
| keywords |
ai
anthropic
claude
sdk
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# Claude Code SDK for Python
Python SDK for Claude Code. See the [Claude Code SDK documentation](https://docs.anthropic.com/en/docs/claude-code/sdk) for more information.
## Installation
```bash
pip install claude-code-sdk
```
**Prerequisites:**
- Python 3.10+
- Node.js
- Claude Code: `npm install -g @anthropic-ai/claude-code`
## Quick Start
```python
import anyio
from claude_code_sdk import query
async def main():
async for message in query(prompt="What is 2 + 2?"):
print(message)
anyio.run(main)
```
## Usage
### Basic Query
```python
from claude_code_sdk import query, ClaudeCodeOptions, AssistantMessage, TextBlock
# Simple query
async for message in query(prompt="Hello Claude"):
if isinstance(message, AssistantMessage):
for block in message.content:
if isinstance(block, TextBlock):
print(block.text)
# With options
options = ClaudeCodeOptions(
system_prompt="You are a helpful assistant",
max_turns=1
)
async for message in query(prompt="Tell me a joke", options=options):
print(message)
```
### Using Tools
```python
options = ClaudeCodeOptions(
allowed_tools=["Read", "Write", "Bash"],
permission_mode='acceptEdits' # auto-accept file edits
)
async for message in query(
prompt="Create a hello.py file",
options=options
):
# Process tool use and results
pass
```
### Working Directory
```python
from pathlib import Path
options = ClaudeCodeOptions(
cwd="/path/to/project" # or Path("/path/to/project")
)
```
## API Reference
### `query(prompt, options=None)`
Main async function for querying Claude.
**Parameters:**
- `prompt` (str): The prompt to send to Claude
- `options` (ClaudeCodeOptions): Optional configuration
**Returns:** AsyncIterator[Message] - Stream of response messages
### Types
See [src/claude_code_sdk/types.py](src/claude_code_sdk/types.py) for complete type definitions:
- `ClaudeCodeOptions` - Configuration options
- `AssistantMessage`, `UserMessage`, `SystemMessage`, `ResultMessage` - Message types
- `TextBlock`, `ToolUseBlock`, `ToolResultBlock` - Content blocks
## Error Handling
```python
from claude_code_sdk import (
ClaudeSDKError, # Base error
CLINotFoundError, # Claude Code not installed
CLIConnectionError, # Connection issues
ProcessError, # Process failed
CLIJSONDecodeError, # JSON parsing issues
)
try:
async for message in query(prompt="Hello"):
pass
except CLINotFoundError:
print("Please install Claude Code")
except ProcessError as e:
print(f"Process failed with exit code: {e.exit_code}")
except CLIJSONDecodeError as e:
print(f"Failed to parse response: {e}")
```
See [src/claude_code_sdk/_errors.py](src/claude_code_sdk/_errors.py) for all error types.
## Available Tools
See the [Claude Code documentation](https://docs.anthropic.com/en/docs/claude-code/settings#tools-available-to-claude) for a complete list of available tools.
## Examples
See [examples/quick_start.py](examples/quick_start.py) for a complete working example.
## License
MIT
Raw data
{
"_id": null,
"home_page": null,
"name": "claude-code-sdk",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "ai, anthropic, claude, sdk",
"author": null,
"author_email": "Anthropic <support@anthropic.com>",
"download_url": "https://files.pythonhosted.org/packages/5b/51/ed3bdf0e316c6df2938fae41b914d45f7f5e486053aca99e59d452b0c2d7/claude_code_sdk-0.0.21.tar.gz",
"platform": null,
"description": "# Claude Code SDK for Python\n\nPython SDK for Claude Code. See the [Claude Code SDK documentation](https://docs.anthropic.com/en/docs/claude-code/sdk) for more information.\n\n## Installation\n\n```bash\npip install claude-code-sdk\n```\n\n**Prerequisites:**\n- Python 3.10+\n- Node.js \n- Claude Code: `npm install -g @anthropic-ai/claude-code`\n\n## Quick Start\n\n```python\nimport anyio\nfrom claude_code_sdk import query\n\nasync def main():\n async for message in query(prompt=\"What is 2 + 2?\"):\n print(message)\n\nanyio.run(main)\n```\n\n## Usage\n\n### Basic Query\n\n```python\nfrom claude_code_sdk import query, ClaudeCodeOptions, AssistantMessage, TextBlock\n\n# Simple query\nasync for message in query(prompt=\"Hello Claude\"):\n if isinstance(message, AssistantMessage):\n for block in message.content:\n if isinstance(block, TextBlock):\n print(block.text)\n\n# With options\noptions = ClaudeCodeOptions(\n system_prompt=\"You are a helpful assistant\",\n max_turns=1\n)\n\nasync for message in query(prompt=\"Tell me a joke\", options=options):\n print(message)\n```\n\n### Using Tools\n\n```python\noptions = ClaudeCodeOptions(\n allowed_tools=[\"Read\", \"Write\", \"Bash\"],\n permission_mode='acceptEdits' # auto-accept file edits\n)\n\nasync for message in query(\n prompt=\"Create a hello.py file\", \n options=options\n):\n # Process tool use and results\n pass\n```\n\n### Working Directory\n\n```python\nfrom pathlib import Path\n\noptions = ClaudeCodeOptions(\n cwd=\"/path/to/project\" # or Path(\"/path/to/project\")\n)\n```\n\n\n## API Reference\n\n### `query(prompt, options=None)`\n\nMain async function for querying Claude.\n\n**Parameters:**\n- `prompt` (str): The prompt to send to Claude\n- `options` (ClaudeCodeOptions): Optional configuration\n\n**Returns:** AsyncIterator[Message] - Stream of response messages\n\n### Types\n\nSee [src/claude_code_sdk/types.py](src/claude_code_sdk/types.py) for complete type definitions:\n- `ClaudeCodeOptions` - Configuration options\n- `AssistantMessage`, `UserMessage`, `SystemMessage`, `ResultMessage` - Message types\n- `TextBlock`, `ToolUseBlock`, `ToolResultBlock` - Content blocks\n\n## Error Handling\n\n```python\nfrom claude_code_sdk import (\n ClaudeSDKError, # Base error\n CLINotFoundError, # Claude Code not installed\n CLIConnectionError, # Connection issues\n ProcessError, # Process failed\n CLIJSONDecodeError, # JSON parsing issues\n)\n\ntry:\n async for message in query(prompt=\"Hello\"):\n pass\nexcept CLINotFoundError:\n print(\"Please install Claude Code\")\nexcept ProcessError as e:\n print(f\"Process failed with exit code: {e.exit_code}\")\nexcept CLIJSONDecodeError as e:\n print(f\"Failed to parse response: {e}\")\n```\n\nSee [src/claude_code_sdk/_errors.py](src/claude_code_sdk/_errors.py) for all error types.\n\n## Available Tools\n\nSee the [Claude Code documentation](https://docs.anthropic.com/en/docs/claude-code/settings#tools-available-to-claude) for a complete list of available tools.\n\n## Examples\n\nSee [examples/quick_start.py](examples/quick_start.py) for a complete working example.\n\n## License\n\nMIT\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python SDK for Claude Code",
"version": "0.0.21",
"project_urls": {
"Documentation": "https://docs.anthropic.com/en/docs/claude-code/sdk",
"Homepage": "https://github.com/anthropics/claude-code-sdk-python",
"Issues": "https://github.com/anthropics/claude-code-sdk-python/issues"
},
"split_keywords": [
"ai",
" anthropic",
" claude",
" sdk"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "70031c29bdd0124ae92e256de24071dc3cccb838bb70f535db0614ff6e7b645f",
"md5": "e7d56e29dd52c9e2129d07d43a749512",
"sha256": "36b6741064959de7782360e7c066d1e45d175675ba7561a657820162fb817db7"
},
"downloads": -1,
"filename": "claude_code_sdk-0.0.21-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e7d56e29dd52c9e2129d07d43a749512",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 27754,
"upload_time": "2025-09-05T20:39:46",
"upload_time_iso_8601": "2025-09-05T20:39:46.178410Z",
"url": "https://files.pythonhosted.org/packages/70/03/1c29bdd0124ae92e256de24071dc3cccb838bb70f535db0614ff6e7b645f/claude_code_sdk-0.0.21-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "5b51ed3bdf0e316c6df2938fae41b914d45f7f5e486053aca99e59d452b0c2d7",
"md5": "4d37a7c70e0a58c8fb94a97732a51da8",
"sha256": "780759353fddb547df1db5df30ea8e5a891f6a8a7b78bd8b52bea9c5f45038ad"
},
"downloads": -1,
"filename": "claude_code_sdk-0.0.21.tar.gz",
"has_sig": false,
"md5_digest": "4d37a7c70e0a58c8fb94a97732a51da8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 36552,
"upload_time": "2025-09-05T20:39:47",
"upload_time_iso_8601": "2025-09-05T20:39:47.432283Z",
"url": "https://files.pythonhosted.org/packages/5b/51/ed3bdf0e316c6df2938fae41b914d45f7f5e486053aca99e59d452b0c2d7/claude_code_sdk-0.0.21.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-05 20:39:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "anthropics",
"github_project": "claude-code-sdk-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "claude-code-sdk"
}