# metorial-anthropic
Anthropic (Claude) provider integration for Metorial.
## Installation
```bash
pip install metorial-anthropic
# or
uv add metorial-anthropic
# or
poetry add metorial-anthropic
```
## Features
- š¤ **Claude Integration**: Full support for Claude 3.5, Claude 3, and other Anthropic models
- š ļø **Tool Calling**: Native Anthropic tool format support
- š” **Session Management**: Automatic tool lifecycle handling
- š **Format Conversion**: Converts Metorial tools to Anthropic tool format
- ā” **Async Support**: Full async/await support
## Supported Models
All Anthropic Claude models that support tool calling:
- `claude-3-5-sonnet-20241022`: Latest Claude 3.5 Sonnet with enhanced capabilities
- `claude-3-5-haiku-20241022`: Fastest Claude 3.5 model
- `claude-3-opus-20240229`: Most capable Claude 3 model
- `claude-3-sonnet-20240229`: Balanced Claude 3 model
- `claude-3-haiku-20240307`: Fastest Claude 3 model
## Usage
### Quick Start (Recommended)
```python
import asyncio
from anthropic import AsyncAnthropic
from metorial import Metorial
async def main():
# Initialize clients
metorial = Metorial(api_key="...your-metorial-api-key...") # async by default
anthropic_client = AsyncAnthropic(
api_key="...your-anthropic-api-key..."
)
# One-liner chat with automatic session management
response = await metorial.run(
"What are the latest commits in the metorial/websocket-explorer repository?",
"...your-mcp-server-deployment-id...", # can also be list
anthropic_client,
model="claude-3-5-sonnet-20241022",
max_iterations=25
)
print("Response:", response)
asyncio.run(main())
```
### Streaming Chat
```python
import asyncio
from anthropic import AsyncAnthropic
from metorial import Metorial
from metorial.types import StreamEventType
async def streaming_example():
# Initialize clients
metorial = Metorial(api_key="...your-metorial-api-key...")
anthropic_client = AsyncAnthropic(
api_key="...your-anthropic-api-key..."
)
# Streaming chat with real-time responses
async def stream_action(session):
messages = [
{"role": "user", "content": "Explain quantum computing"}
]
async for event in metorial.stream(
anthropic_client, session, messages,
model="claude-3-5-sonnet-20241022",
max_iterations=25
):
if event.type == StreamEventType.CONTENT:
print(f"š¤ {event.content}", end="", flush=True)
elif event.type == StreamEventType.TOOL_CALL:
print(f"\nš§ Executing {len(event.tool_calls)} tool(s)...")
elif event.type == StreamEventType.COMPLETE:
print(f"\nā
Complete!")
await metorial.with_session("...your-server-deployment-id...", stream_action)
asyncio.run(streaming_example())
```
### Advanced Usage with Session Management
```python
import asyncio
from anthropic import Anthropic
from metorial import Metorial
from metorial_anthropic import MetorialAnthropicSession
async def main():
# Initialize clients
metorial = Metorial(api_key="...your-metorial-api-key...")
anthropic = Anthropic(api_key="...your-anthropic-api-key...")
# Create session with your server deployments
async with metorial.session(["...your-server-deployment-id..."]) as session:
# Create Anthropic-specific wrapper
anthropic_session = MetorialAnthropicSession(session.tool_manager)
messages = [
{"role": "user", "content": "What are the latest commits?"}
]
# Remove duplicate tools by name (Anthropic requirement)
unique_tools = list({t["name"]: t for t in anthropic_session.tools}.values())
response = await anthropic.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=messages,
tools=unique_tools
)
# Handle tool calls
tool_calls = [c for c in response.content if c.type == "tool_use"]
if tool_calls:
tool_response = await anthropic_session.call_tools(tool_calls)
messages.append({"role": "assistant", "content": response.content})
messages.append(tool_response)
# Continue conversation...
asyncio.run(main())
```
### Using Convenience Functions
```python
from metorial_anthropic import build_anthropic_tools, call_anthropic_tools
async def example_with_functions():
# Get tools in Anthropic format
tools = build_anthropic_tools(tool_manager)
# Call tools from Anthropic response
tool_response = await call_anthropic_tools(tool_manager, tool_calls)
```
## API Reference
### `MetorialAnthropicSession`
Main session class for Anthropic integration.
```python
session = MetorialAnthropicSession(tool_manager)
```
**Properties:**
- `tools`: List of tools in Anthropic format
**Methods:**
- `async call_tools(tool_calls)`: Execute tool calls and return user message
### `build_anthropic_tools(tool_mgr)`
Build Anthropic-compatible tool definitions.
**Returns:** List of tool definitions in Anthropic format
### `call_anthropic_tools(tool_mgr, tool_calls)`
Execute tool calls from Anthropic response.
**Returns:** User message with tool results
## Tool Format
Tools are converted to Anthropic's format:
```python
{
"name": "tool_name",
"description": "Tool description",
"input_schema": {
"type": "object",
"properties": {...},
"required": [...]
}
}
```
## Error Handling
```python
try:
tool_response = await anthropic_session.call_tools(tool_calls)
except Exception as e:
print(f"Tool execution failed: {e}")
```
Tool errors are returned as error messages in the response format.
## License
MIT License - see [LICENSE](../../LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "metorial-anthropic",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "ai, anthropic, claude, llm, metorial",
"author": null,
"author_email": "Metorial Team <support@metorial.com>",
"download_url": "https://files.pythonhosted.org/packages/9a/52/a294ac45f4ef5d812da35b3639985410a8ed281718138a2032c3ad16e9c1/metorial_anthropic-1.0.4.tar.gz",
"platform": null,
"description": "# metorial-anthropic\n\nAnthropic (Claude) provider integration for Metorial.\n\n## Installation\n\n```bash\npip install metorial-anthropic\n# or\nuv add metorial-anthropic\n# or\npoetry add metorial-anthropic\n```\n\n## Features\n\n- \ud83e\udd16 **Claude Integration**: Full support for Claude 3.5, Claude 3, and other Anthropic models\n- \ud83d\udee0\ufe0f **Tool Calling**: Native Anthropic tool format support\n- \ud83d\udce1 **Session Management**: Automatic tool lifecycle handling\n- \ud83d\udd04 **Format Conversion**: Converts Metorial tools to Anthropic tool format\n- \u26a1 **Async Support**: Full async/await support\n\n## Supported Models\n\nAll Anthropic Claude models that support tool calling:\n\n- `claude-3-5-sonnet-20241022`: Latest Claude 3.5 Sonnet with enhanced capabilities\n- `claude-3-5-haiku-20241022`: Fastest Claude 3.5 model\n- `claude-3-opus-20240229`: Most capable Claude 3 model\n- `claude-3-sonnet-20240229`: Balanced Claude 3 model\n- `claude-3-haiku-20240307`: Fastest Claude 3 model\n\n## Usage\n\n### Quick Start (Recommended)\n\n```python\nimport asyncio\nfrom anthropic import AsyncAnthropic\nfrom metorial import Metorial\n\nasync def main():\n # Initialize clients\n metorial = Metorial(api_key=\"...your-metorial-api-key...\") # async by default\n anthropic_client = AsyncAnthropic(\n api_key=\"...your-anthropic-api-key...\"\n )\n \n # One-liner chat with automatic session management\n response = await metorial.run(\n \"What are the latest commits in the metorial/websocket-explorer repository?\",\n \"...your-mcp-server-deployment-id...\", # can also be list\n anthropic_client,\n model=\"claude-3-5-sonnet-20241022\",\n max_iterations=25\n )\n \n print(\"Response:\", response)\n\nasyncio.run(main())\n```\n\n### Streaming Chat\n\n```python\nimport asyncio\nfrom anthropic import AsyncAnthropic\nfrom metorial import Metorial\nfrom metorial.types import StreamEventType\n\nasync def streaming_example():\n # Initialize clients\n metorial = Metorial(api_key=\"...your-metorial-api-key...\")\n anthropic_client = AsyncAnthropic(\n api_key=\"...your-anthropic-api-key...\"\n )\n \n # Streaming chat with real-time responses\n async def stream_action(session):\n messages = [\n {\"role\": \"user\", \"content\": \"Explain quantum computing\"}\n ]\n \n async for event in metorial.stream(\n anthropic_client, session, messages, \n model=\"claude-3-5-sonnet-20241022\",\n max_iterations=25\n ):\n if event.type == StreamEventType.CONTENT:\n print(f\"\ud83e\udd16 {event.content}\", end=\"\", flush=True)\n elif event.type == StreamEventType.TOOL_CALL:\n print(f\"\\n\ud83d\udd27 Executing {len(event.tool_calls)} tool(s)...\")\n elif event.type == StreamEventType.COMPLETE:\n print(f\"\\n\u2705 Complete!\")\n \n await metorial.with_session(\"...your-server-deployment-id...\", stream_action)\n\nasyncio.run(streaming_example())\n```\n\n### Advanced Usage with Session Management\n\n```python\nimport asyncio\nfrom anthropic import Anthropic\nfrom metorial import Metorial\nfrom metorial_anthropic import MetorialAnthropicSession\n\nasync def main():\n # Initialize clients\n metorial = Metorial(api_key=\"...your-metorial-api-key...\")\n anthropic = Anthropic(api_key=\"...your-anthropic-api-key...\")\n \n # Create session with your server deployments\n async with metorial.session([\"...your-server-deployment-id...\"]) as session:\n # Create Anthropic-specific wrapper\n anthropic_session = MetorialAnthropicSession(session.tool_manager)\n \n messages = [\n {\"role\": \"user\", \"content\": \"What are the latest commits?\"}\n ]\n \n # Remove duplicate tools by name (Anthropic requirement)\n unique_tools = list({t[\"name\"]: t for t in anthropic_session.tools}.values())\n \n response = await anthropic.messages.create(\n model=\"claude-3-5-sonnet-20241022\",\n max_tokens=1024,\n messages=messages,\n tools=unique_tools\n )\n \n # Handle tool calls\n tool_calls = [c for c in response.content if c.type == \"tool_use\"]\n if tool_calls:\n tool_response = await anthropic_session.call_tools(tool_calls)\n messages.append({\"role\": \"assistant\", \"content\": response.content})\n messages.append(tool_response)\n \n # Continue conversation...\n\nasyncio.run(main())\n```\n\n### Using Convenience Functions\n\n```python\nfrom metorial_anthropic import build_anthropic_tools, call_anthropic_tools\n\nasync def example_with_functions():\n # Get tools in Anthropic format\n tools = build_anthropic_tools(tool_manager)\n \n # Call tools from Anthropic response\n tool_response = await call_anthropic_tools(tool_manager, tool_calls)\n```\n\n## API Reference\n\n### `MetorialAnthropicSession`\n\nMain session class for Anthropic integration.\n\n```python\nsession = MetorialAnthropicSession(tool_manager)\n```\n\n**Properties:**\n- `tools`: List of tools in Anthropic format\n\n**Methods:**\n- `async call_tools(tool_calls)`: Execute tool calls and return user message\n\n### `build_anthropic_tools(tool_mgr)`\n\nBuild Anthropic-compatible tool definitions.\n\n**Returns:** List of tool definitions in Anthropic format\n\n### `call_anthropic_tools(tool_mgr, tool_calls)`\n\nExecute tool calls from Anthropic response.\n\n**Returns:** User message with tool results\n\n## Tool Format\n\nTools are converted to Anthropic's format:\n\n```python\n{\n \"name\": \"tool_name\",\n \"description\": \"Tool description\",\n \"input_schema\": {\n \"type\": \"object\",\n \"properties\": {...},\n \"required\": [...]\n }\n}\n```\n\n## Error Handling\n\n```python\ntry:\n tool_response = await anthropic_session.call_tools(tool_calls)\nexcept Exception as e:\n print(f\"Tool execution failed: {e}\")\n```\n\nTool errors are returned as error messages in the response format.\n\n## License\n\nMIT License - see [LICENSE](../../LICENSE) file for details.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Anthropic (Claude) provider for Metorial",
"version": "1.0.4",
"project_urls": {
"Documentation": "https://metorial.com/docs",
"Homepage": "https://metorial.com",
"Repository": "https://github.com/metorial/metorial-python"
},
"split_keywords": [
"ai",
" anthropic",
" claude",
" llm",
" metorial"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "d6232d965679610e708567cccbd8a9d4584f71a48d2a916fdbe2ee6fadf0b44c",
"md5": "8f54b06e0b614905687f1ea6d5924057",
"sha256": "7333b2bd88ad6c7390035c832db27e6c0093efc2c2ad533e619b4f35119f6d9a"
},
"downloads": -1,
"filename": "metorial_anthropic-1.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8f54b06e0b614905687f1ea6d5924057",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 6699,
"upload_time": "2025-10-30T05:03:10",
"upload_time_iso_8601": "2025-10-30T05:03:10.012001Z",
"url": "https://files.pythonhosted.org/packages/d6/23/2d965679610e708567cccbd8a9d4584f71a48d2a916fdbe2ee6fadf0b44c/metorial_anthropic-1.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "9a52a294ac45f4ef5d812da35b3639985410a8ed281718138a2032c3ad16e9c1",
"md5": "13ecf6a18e739695370b1cd180ef069f",
"sha256": "bf97dad490984db5ddfcb27ba692d1b239394e52e77d362e15200f9f1fcdb6c2"
},
"downloads": -1,
"filename": "metorial_anthropic-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "13ecf6a18e739695370b1cd180ef069f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 7670,
"upload_time": "2025-10-30T05:03:11",
"upload_time_iso_8601": "2025-10-30T05:03:11.610885Z",
"url": "https://files.pythonhosted.org/packages/9a/52/a294ac45f4ef5d812da35b3639985410a8ed281718138a2032c3ad16e9c1/metorial_anthropic-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-30 05:03:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "metorial",
"github_project": "metorial-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "metorial-anthropic"
}