Skip to main content

Python SDK for Ratel — context engineering platform for AI agents. BM25 tool retrieval, MCP ingestion, framework-neutral gateway tools.

Project description

ratel-ai

Python SDK for Ratel — drop context engineering into any Python agent with one dependency.

DocsRoadmapDiscord

Python SDK for Ratel. Bundles ratel-ai-core (Rust) via PyO3 so Python agents can drop Ratel in with one dependency — no Rust toolchain, no service to deploy.

Binding strategy is locked in ADR 0011; it mirrors the TypeScript SDK's NAPI binding (ADR 0002).

Install

pip install ratel-ai
# upstream MCP ingestion (register_mcp_server) needs the extra:
pip install 'ratel-ai[mcp]'

Prebuilt abi3 wheels ship for darwin-arm64, darwin-x64, linux-x64-gnu, linux-arm64-gnu, and win32-x64-msvc — no Rust toolchain required to install. The base SDK runs on CPython ≥ 3.9; the mcp extra requires ≥ 3.10.

Usage

The SDK exposes two layers, both framework-neutral — the Python mirror of the TypeScript SDK.

ToolRegistry — metadata-only BM25 index

from ratel_ai import ToolRegistry

registry = ToolRegistry()
registry.register(
    "read_file",
    "read_file",
    "Read a file from local disk and return its textual contents.",
    {"properties": {"path": {"type": "string"}}},
    {"properties": {"contents": {"type": "string"}}},
)

hits = registry.search("read a text file", 5)
# [SearchHit(tool_id="read_file", score=1.42), ...]

ToolCatalog + gateway tools — register once, dispatch by id

ToolCatalog extends the registry with executable handlers (id → execute), and search_capabilities_tool / invoke_tool_tool give your agent a self-service gateway over the catalog. Pair them with any agent framework — see examples/pydantic-ai/ for a Pydantic AI wiring.

import asyncio
from ratel_ai import ToolCatalog, ExecutableTool, search_capabilities_tool, invoke_tool_tool

catalog = ToolCatalog()
catalog.register(
    ExecutableTool(
        id="read_file",
        name="read_file",
        description="Read a file from local disk.",
        input_schema={"properties": {"path": {"type": "string"}}},
        output_schema={"properties": {"contents": {"type": "string"}}},
        execute=lambda args: {"contents": open(args["path"]).read()},
    )
)

search = search_capabilities_tool(catalog)   # id == "search_capabilities"
invoke = invoke_tool_tool(catalog)    # id == "invoke_tool"

Executors may be sync or async; ToolCatalog.invoke awaits coroutines automatically.

SkillCatalog + get_skill_content_tool — reusable playbooks, on demand

Skills are Markdown playbooks ranked by a separate BM25 corpus. When a SkillCatalog is passed to search_capabilities_tool, the search returns a skills bucket alongside tools — each with its own result budget, so a relevant skill is never crowded out by matching tools. The agent loads a skill's full body on demand via get_skill_content_tool.

A skill can also declare the tools its instructions call: when the skill matches, those tools are pulled into the tools bucket (additively, deduped), so the agent gets the playbook and the tools it needs in a single turn instead of a second search.

from ratel_ai import Skill, SkillCatalog, get_skill_content_tool, search_capabilities_tool

skills = SkillCatalog()
skills.register(
    Skill(
        id="vercel-deploy",
        name="vercel-deploy",
        description="How to deploy to Vercel: env vars, preview vs production, rollbacks.",
        tags=["deploy", "ship to production"],     # indexed for ranking
        tools=["vercel__deploy", "fs__read_file"],  # surfaced with the skill
        metadata={"stacks": ["next", "vercel"]},   # non-indexed context (push ranker)
    )
)

search = search_capabilities_tool(catalog, skills)  # result: {"tools": {...}, "skills": [...]}
load = get_skill_content_tool(skills)               # id == "get_skill_content"

register_mcp_server — ingest an upstream MCP server

Requires the mcp extra. The caller owns the ClientSession lifecycle (set it up with async with) and passes the initialized session in:

from ratel_ai import register_mcp_server

handle = await register_mcp_server(
    catalog, name="github", session=session, transport_label="stdio",
)
# handle.tool_ids -> ["github__create_issue", ...]

Telemetry

Pass trace to ToolCatalog to capture every search / invoke / gateway / upstream / auth event into a sink owned by the Rust core (ADR 0009). Default is no-op — nothing is captured unless you opt in.

from ratel_ai import ToolCatalog, TraceSinkConfig

catalog = ToolCatalog(
    trace=TraceSinkConfig(kind="jsonl", session_id="session-1", path="/tmp/ratel.jsonl"),
)
# every catalog.invoke, search_capabilities_tool, register_mcp_server call now writes
# one JSON line per event to /tmp/ratel.jsonl.

Sink kinds:

  • kind="noop" — drop everything (default).
  • kind="memory", session_id — keep events in memory; drain via catalog.drain_trace_events(). Useful for tests.
  • kind="jsonl", session_id, path — append one JSON line per event to path (mode 0600 on Unix). Best-effort, lossy on backpressure — see ADR-0009 for the reliability profile.

search_capabilities_tool tags its emitted search event with origin="agent"; direct callers (catalog.search(query, k)) default to "direct". Override per call via catalog.search(query, k, "agent").

Develop

This package is part of the Cargo workspace at the repo root and builds into a local venv. From src/sdk/python/:

uv venv --python 3.11 .venv
uv pip install --python .venv maturin pytest pytest-asyncio ruff mypy
.venv/bin/maturin develop        # build the native extension into the venv
.venv/bin/pytest                 # run tests
.venv/bin/ruff check .           # lint
.venv/bin/mypy ratel_ai          # type-check

Layout

native/         PyO3 binding to ratel-ai-core (cdylib Cargo workspace member)
ratel_ai/       pure-Python SDK: catalog, gateway tools, MCP ingestion
tests/          pytest suite
pyproject.toml  maturin build backend + tooling config

The native crate is a member of the top-level Cargo workspace, so cargo build --workspace picks it up automatically.

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

ratel_ai-0.2.0.tar.gz (44.5 kB view details)

Uploaded Source

Built Distributions

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

ratel_ai-0.2.0-cp39-abi3-win_amd64.whl (646.3 kB view details)

Uploaded CPython 3.9+Windows x86-64

ratel_ai-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (820.0 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

ratel_ai-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (844.1 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

ratel_ai-0.2.0-cp39-abi3-macosx_11_0_arm64.whl (744.8 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

ratel_ai-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl (751.5 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file ratel_ai-0.2.0.tar.gz.

File metadata

  • Download URL: ratel_ai-0.2.0.tar.gz
  • Upload date:
  • Size: 44.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ratel_ai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d0fc9a9b818741bebf192bad3a5aef421be8363b385d99ac12b0417c42f82ed8
MD5 a40818dd2a6d5c889573e84840dfdbe8
BLAKE2b-256 f04d8d6be4da348c4c0644e481a29aeba530808f538c11d6ffd0aab16a0bbf3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ratel_ai-0.2.0.tar.gz:

Publisher: release.yml on ratel-ai/ratel

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

File details

Details for the file ratel_ai-0.2.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: ratel_ai-0.2.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 646.3 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ratel_ai-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9aa4e85f2a802b62f15c3e19b138b5791eb7255be695efa44427191ee9036eb7
MD5 40b24d34f71bef80d1249fa7def319c6
BLAKE2b-256 65dc544fc3df923a5b8b3f63522f0b72c9be338d47dcca19cfac3cd3eed761a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for ratel_ai-0.2.0-cp39-abi3-win_amd64.whl:

Publisher: release.yml on ratel-ai/ratel

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

File details

Details for the file ratel_ai-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ratel_ai-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 782e30bcfad363539b1e35437a5faababb959ac1f1ca0063159ea601d147e5fb
MD5 c9337032bbedfd969d6dd9ed152bc8fd
BLAKE2b-256 8492840fe18e7325c4e45f50d437b60a3b384e7bafddf5bd5c848606be887098

See more details on using hashes here.

Provenance

The following attestation bundles were made for ratel_ai-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on ratel-ai/ratel

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

File details

Details for the file ratel_ai-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ratel_ai-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b86a37362b79a3940a486a6f2ae422275efaf2d004a46c78634c5208095b9995
MD5 4a282a09267f71f7f5a5160f5faf0eef
BLAKE2b-256 6a0912cfb9068368f0eca4acef346884ed5cd56403f4255aa1edcd25adb8105a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ratel_ai-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on ratel-ai/ratel

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

File details

Details for the file ratel_ai-0.2.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ratel_ai-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f37e401072fd4e104f074b93456cd4347f2466499cbc11696725fdf68e7061b0
MD5 9c845ee5803f2e8fa72c30db2e136e10
BLAKE2b-256 3f4b39277e28722b6d1d71f917706909e1515ec643074fd20028f9344348abbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for ratel_ai-0.2.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on ratel-ai/ratel

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

File details

Details for the file ratel_ai-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ratel_ai-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3d3617b134f1e81041cb18c05ea4241dd28285b3e8ca110809cb18e722f31b9d
MD5 76d9800665562b32b4a98ad77dbd75a9
BLAKE2b-256 4a97db501b4ba55ddd8a9138df61651341a6dc5dcfdaefc957086bddad4e76e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for ratel_ai-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on ratel-ai/ratel

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

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