Make Claude Code available to Pydantic AI
Project description
clowclow
Make Claude Code available to Pydantic AI using the Claude Agent SDK.
Overview
clowclow is a Python package that bridges the Claude Agent SDK with Pydantic AI, allowing you to use Claude Code's powerful capabilities within Pydantic AI agents.
⚠️ Early Release: This package is in early development and was built with Claude Code (vibe coding with basic checks but no deep warranty). Many features may be broken or incomplete. Use at your own risk and please report issues!
Installation
pip install clowclow
Authentication
You can use clowclow in two ways:
With Claude Code Subscription (No API Key Required)
If you have an active Claude Code subscription, the package will automatically connect to the Claude Code CLI without requiring an API key.
from clowclow import ClaudeCodeModel
# No API key needed with subscription
model = ClaudeCodeModel()
With Anthropic API Key
Alternatively, you can use your Anthropic API key:
export ANTHROPIC_API_KEY="your-api-key"
Or pass it explicitly:
model = ClaudeCodeModel(api_key="your-api-key")
Quick Start
from pydantic_ai import Agent
from clowclow import ClaudeCodeModel
# Create a ClaudeCodeModel instance
model = ClaudeCodeModel()
# Use it with a Pydantic AI Agent
agent = Agent(model)
# Run queries
result = agent.run_sync("What is 2+2?")
print(result.output)
Features
- Full Pydantic AI Integration: Works seamlessly with Pydantic AI's Agent interface
- Structured Output: Support for Pydantic models as output types using
<schema>tag method - Function Tool Calling: MCP-based integration for Pydantic AI function tools
- Streaming: Supports streaming responses
- Multimodal: Handle images and other content types
- Claude Agent SDK: Leverages the official Claude Agent SDK for extended capabilities
Usage Examples
Basic Text Query
from pydantic_ai import Agent
from clowclow import ClaudeCodeModel
model = ClaudeCodeModel()
agent = Agent(model, system_prompt="You are a helpful assistant.")
result = agent.run_sync("Tell me a joke")
print(result.output)
Structured Output
from pydantic import BaseModel
from pydantic_ai import Agent
from clowclow import ClaudeCodeModel
class CityInfo(BaseModel):
city: str
country: str
population: int
model = ClaudeCodeModel()
agent = Agent(model, result_type=CityInfo)
result = agent.run_sync("What is the largest city in France?")
print(f"{result.output.city}, {result.output.country}")
With Tools
from pydantic_ai import Agent
from clowclow import ClaudeCodeModel
model = ClaudeCodeModel()
agent = Agent(model)
@agent.tool_plain
def get_weather(city: str) -> str:
"""Get weather for a city."""
return f"Weather in {city}: Sunny, 22°C"
result = agent.run_sync("What's the weather in Paris?")
print(result.output)
Multimodal (Images)
from pydantic_ai import Agent
from pydantic_ai.messages import ImageUrl
from clowclow import ClaudeCodeModel
model = ClaudeCodeModel()
agent = Agent(model)
result = agent.run_sync([
"What's in this image?",
ImageUrl(url="https://example.com/image.jpg")
])
print(result.output)
Streaming
import asyncio
from pydantic_ai import Agent
from clowclow import ClaudeCodeModel
async def stream_example():
model = ClaudeCodeModel()
agent = Agent(model)
async with agent.run_stream("Write a short poem") as result:
async for chunk in result.stream_text(debounce_by=None):
print(chunk, end="", flush=True)
asyncio.run(stream_example())
Configuration
Workspace Directory
Specify a custom workspace directory for temporary files:
from pathlib import Path
model = ClaudeCodeModel(workspace_dir=Path("/path/to/workspace"))
Custom Model Name
model = ClaudeCodeModel(model_name="custom-claude-code")
Requirements
- Python 3.13+
- claude-agent-sdk >= 0.1.0
- pydantic-ai >= 1.0.5
Development
Install Development Dependencies
pip install -e ".[dev]"
Run Tests
pytest
Run Tests with Coverage
uv run coverage run -m pytest && uv run coverage report
License
MIT License
Copyright (c) 2025 clowclow contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Known Issues
As this is an early release, you may encounter:
- Incomplete feature implementations
- Edge cases that aren't handled properly
- Breaking changes in future versions
- Compatibility issues with certain Pydantic AI features
Please report any issues on the GitHub issue tracker.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clowclow-0.2.0.tar.gz.
File metadata
- Download URL: clowclow-0.2.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5a252c41ed1332fa6a5ee73e49e0fe7773c9d92d00766635f80a91a6c3af61c
|
|
| MD5 |
aa416ec03f279bae5730f87627ce9b31
|
|
| BLAKE2b-256 |
97189432f974e927713d388143fb49d6c3682f715502ca4fc659a44d059dd28f
|
File details
Details for the file clowclow-0.2.0-py3-none-any.whl.
File metadata
- Download URL: clowclow-0.2.0-py3-none-any.whl
- Upload date:
- Size: 20.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a316d1296fec96f4becac4eeebd1976994a3bf1850426920acd7acaf10488a3f
|
|
| MD5 |
8eceb2674f491e648a46816f84f4c0b7
|
|
| BLAKE2b-256 |
dcb929170d7c2e83d51f8ccaeefbc20de01fbd061f960f6e329e32d5adc15318
|