Anthropic (Claude) provider for Metorial
Project description
metorial-anthropic
Anthropic (Claude) provider integration for Metorial.
Installation
pip install metorial anthropic
Quick Start
import asyncio
from metorial import Metorial, MetorialAnthropic
from anthropic import AsyncAnthropic
metorial = Metorial(api_key="your-metorial-api-key")
anthropic = AsyncAnthropic(api_key="your-anthropic-api-key")
async def main():
async def session_handler(session):
messages = [{"role": "user", "content": "What's the latest news?"}]
for _ in range(10):
response = await anthropic.messages.create(
model="claude-sonnet-4-5",
max_tokens=1024,
messages=messages,
tools=session["tools"]
)
tool_calls = [b for b in response.content if b.type == "tool_use"]
if not tool_calls:
print(response.content[0].text)
break
tool_responses = await session["callTools"](tool_calls)
messages.append({"role": "assistant", "content": response.content})
messages.append(tool_responses)
await session["closeSession"]()
await metorial.with_provider_session(
MetorialAnthropic,
{"serverDeployments": [{"serverDeploymentId": "your-server-deployment-id"}]},
session_handler
)
asyncio.run(main())
Streaming
import asyncio
from metorial import Metorial, MetorialAnthropic
from anthropic import AsyncAnthropic
metorial = Metorial(api_key="your-metorial-api-key")
anthropic = AsyncAnthropic(api_key="your-anthropic-api-key")
async def main():
async def session_handler(session):
messages = [{"role": "user", "content": "What's the latest news?"}]
for _ in range(10):
async with anthropic.messages.stream(
model="claude-sonnet-4-5",
max_tokens=1024,
messages=messages,
tools=session["tools"]
) as stream:
async for text in stream.text_stream:
print(text, end="", flush=True)
response = await stream.get_final_message()
tool_calls = [b for b in response.content if b.type == "tool_use"]
if not tool_calls:
print()
break
tool_responses = await session["callTools"](tool_calls)
messages.append({"role": "assistant", "content": response.content})
messages.append(tool_responses)
await session["closeSession"]()
await metorial.with_provider_session(
MetorialAnthropic,
{
"serverDeployments": [{"serverDeploymentId": "your-server-deployment-id"}],
"streaming": True, # Required for streaming with tool calls
},
session_handler
)
asyncio.run(main())
Supported Models
All Anthropic Claude models that support tool calling:
claude-sonnet-4-5: Latest Claude Sonnetclaude-opus-4: Most capable Claude modelclaude-3-5-sonnet-20241022: Claude 3.5 Sonnetclaude-3-5-haiku-20241022: Fastest Claude 3.5 model
Session Object
async def session_handler(session):
tools = session["tools"] # Tool definitions in Anthropic format
call_tools = session["callTools"] # Execute tools and get responses
close_session = session["closeSession"] # Close the session when done
Error Handling
from metorial import MetorialAPIError
try:
await metorial.with_provider_session(...)
except MetorialAPIError as e:
print(f"API Error: {e.message} (Status: {e.status})")
except Exception as e:
print(f"Unexpected error: {e}")
License
MIT License - see LICENSE file for details.
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 metorial_anthropic-1.0.5.tar.gz.
File metadata
- Download URL: metorial_anthropic-1.0.5.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9023ebed6ca5925ace95964fa694690bf7e6d8548463a1ead6f5d0bcb11d36d4
|
|
| MD5 |
9e473e097a4b485965c2780f9b56823a
|
|
| BLAKE2b-256 |
ebee73f933e1c5ebe1ddfea5316d4d9983c17a033d08925d939c8bbf52110ae9
|
Provenance
The following attestation bundles were made for metorial_anthropic-1.0.5.tar.gz:
Publisher:
release.yml on metorial/metorial-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metorial_anthropic-1.0.5.tar.gz -
Subject digest:
9023ebed6ca5925ace95964fa694690bf7e6d8548463a1ead6f5d0bcb11d36d4 - Sigstore transparency entry: 776931530
- Sigstore integration time:
-
Permalink:
metorial/metorial-python@ed129f7a01110a9ea3729266af09ac6326785b5e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/metorial
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ed129f7a01110a9ea3729266af09ac6326785b5e -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file metorial_anthropic-1.0.5-py3-none-any.whl.
File metadata
- Download URL: metorial_anthropic-1.0.5-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcefbd560da3b2eba13a2c9837f489ef71eb22dc52625cf98dca3b1fcb775e6c
|
|
| MD5 |
52fbdc846ff5763f3dc4a77cc46aecda
|
|
| BLAKE2b-256 |
5af000a8f069a30277da8d0a0d9c583122eb91e66585488f6790b8e0b03bce36
|
Provenance
The following attestation bundles were made for metorial_anthropic-1.0.5-py3-none-any.whl:
Publisher:
release.yml on metorial/metorial-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metorial_anthropic-1.0.5-py3-none-any.whl -
Subject digest:
bcefbd560da3b2eba13a2c9837f489ef71eb22dc52625cf98dca3b1fcb775e6c - Sigstore transparency entry: 776931545
- Sigstore integration time:
-
Permalink:
metorial/metorial-python@ed129f7a01110a9ea3729266af09ac6326785b5e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/metorial
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ed129f7a01110a9ea3729266af09ac6326785b5e -
Trigger Event:
workflow_dispatch
-
Statement type: