Skip to main content

Metorial Python SDK - Core

The core package for the official Python SDK for Metorial - Connect your AI agents to any MCP server with a single line of code.

Sign up for a free account to get started.

Installation

pip install metorial

Quick Start

pip install metorial anthropic
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 on Hacker 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())

Session Options

Streaming Mode

When using streaming with tool calls, enable the streaming flag:

await metorial.with_provider_session(
    metorial_provider,
    {
        "serverDeployments": [...],
        "streaming": True,  # Required for streaming with tool calls
    },
    session_handler
)

Closing Sessions

Always close your session when done to free up resources:

async def session_handler(session):
    tools = session["tools"]
    close_session = session["closeSession"]

    # Use tools...

    # When finished, close the session
    await close_session()

Session Object

The session object passed to your callback provides:

async def session_handler(session):
    tools = session["tools"]           # Tool definitions formatted for your provider
    call_tools = session["callTools"]  # Execute tools and get responses
    close_session = session["closeSession"]  # Close the session when done (always call this!)

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.

Support

Documentation · GitHub Issues · Email Support

Download files

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

Source Distribution

metorial_core-1.0.12.tar.gz (32.0 kB view details)

Uploaded Source

Built Distribution

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

metorial_core-1.0.12-py3-none-any.whl (46.5 kB view details)

Uploaded Python 3

File details

Details for the file metorial_core-1.0.12.tar.gz.

File metadata

  • Download URL: metorial_core-1.0.12.tar.gz
  • Upload date:
  • Size: 32.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for metorial_core-1.0.12.tar.gz
Algorithm Hash digest
SHA256 1b787124b41edcb1f632d5e7d1e6256cc41739f50ba1386a029f5a4281624905
MD5 bf531ae533a4b5288c07a2e31fd8ca78
BLAKE2b-256 5021bf6dd5225e3347de4d877871afe69204c49d2fc7067c3a735fdbde475e94

See more details on using hashes here.

Provenance

The following attestation bundles were made for metorial_core-1.0.12.tar.gz:

Publisher: release.yml on metorial/metorial-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metorial_core-1.0.12-py3-none-any.whl.

File metadata

  • Download URL: metorial_core-1.0.12-py3-none-any.whl
  • Upload date:
  • Size: 46.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for metorial_core-1.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 1f5ed3e080133141193783ec39e52672476a396d6985275f9497d214416a66ca
MD5 1eb801d0227ae70e70d74e03fef4a3a0
BLAKE2b-256 f51397eb25fd02b4961eb9c83d076b33ba0d8e0a26ee1b3401065bef5b3a9370

See more details on using hashes here.

Provenance

The following attestation bundles were made for metorial_core-1.0.12-py3-none-any.whl:

Publisher: release.yml on metorial/metorial-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.12 This release

2 files

1.0.11

2 files

1.0.10

2 files

1.0.9

2 files

1.0.8

2 files

1.0.6

2 files

1.0.4

2 files

1.0.3

2 files

1.0.1

2 files

Supported by

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