Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clowclow-0.1.1.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clowclow-0.1.1-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file clowclow-0.1.1.tar.gz.

File metadata

  • Download URL: clowclow-0.1.1.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.5

File hashes

Hashes for clowclow-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9cb133bc488cc93d2a34a819df699ad51381c72addbbca2b49e684cb96d70f40
MD5 361b6e707c7a1b0fab1cbfd5501d2ad0
BLAKE2b-256 4eaedcccb4d49fcc35c9f4ebf21ecb40527a2a4f7b5402e85065c65967ef5473

See more details on using hashes here.

File details

Details for the file clowclow-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: clowclow-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.5

File hashes

Hashes for clowclow-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bdfb6774fe5b5756c717e5b475340d6b376786a37156f5d4bbe86646f0f6682e
MD5 bb38f51f0a7cca9be842bf25853735b9
BLAKE2b-256 b4da6168cf4c5a102e51998b174a6d366668662e8e8ab2d748f0ad5141e9ca21

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page