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.
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_tools_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_tools_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_tools_tool(catalog) # id == "search_tools"
invoke = invoke_tool_tool(catalog) # id == "invoke_tool"
Executors may be sync or async; ToolCatalog.invoke awaits coroutines automatically.
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_tools_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 viacatalog.drain_trace_events(). Useful for tests.kind="jsonl",session_id,path— append one JSON line per event topath(mode0600on Unix). Best-effort, lossy on backpressure — see ADR-0009 for the reliability profile.
search_tools_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
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 Distributions
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 ratel_ai-0.1.6.tar.gz.
File metadata
- Download URL: ratel_ai-0.1.6.tar.gz
- Upload date:
- Size: 34.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
042faf848285863a8690d207cf8b0da2bc772ce496ca28c5babf8e1eb60842ab
|
|
| MD5 |
49b5f980f9f7c195f486e2cce07acb98
|
|
| BLAKE2b-256 |
dcebe774327842e40b1685f486fd9ff5b56865a23a53ad456de7398d3bee8d50
|
Provenance
The following attestation bundles were made for ratel_ai-0.1.6.tar.gz:
Publisher:
release.yml on ratel-ai/ratel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ratel_ai-0.1.6.tar.gz -
Subject digest:
042faf848285863a8690d207cf8b0da2bc772ce496ca28c5babf8e1eb60842ab - Sigstore transparency entry: 1778032940
- Sigstore integration time:
-
Permalink:
ratel-ai/ratel@f7ba4b738afc6deb58ca2cce0522f3e6b3ee01f5 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/ratel-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f7ba4b738afc6deb58ca2cce0522f3e6b3ee01f5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ratel_ai-0.1.6-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: ratel_ai-0.1.6-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 608.0 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b33a01a63c51274f52ee077718e62b91f690dfaa86e82de94b9bb25336d4f2d
|
|
| MD5 |
c774781babb1bd8b96dabeb6a95e8b3c
|
|
| BLAKE2b-256 |
db60f8bae54647ce860d0adbde32975ab52ccde9e26281307c052c61ebdc0439
|
Provenance
The following attestation bundles were made for ratel_ai-0.1.6-cp39-abi3-win_amd64.whl:
Publisher:
release.yml on ratel-ai/ratel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ratel_ai-0.1.6-cp39-abi3-win_amd64.whl -
Subject digest:
0b33a01a63c51274f52ee077718e62b91f690dfaa86e82de94b9bb25336d4f2d - Sigstore transparency entry: 1778033049
- Sigstore integration time:
-
Permalink:
ratel-ai/ratel@f7ba4b738afc6deb58ca2cce0522f3e6b3ee01f5 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/ratel-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f7ba4b738afc6deb58ca2cce0522f3e6b3ee01f5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ratel_ai-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: ratel_ai-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 782.4 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a387bc60e0d2c091cb10b691be15a11a93f3bc658c6514b52033b8eee20e4d8
|
|
| MD5 |
a740aacdea34aca9fbf9134f85c3c1a4
|
|
| BLAKE2b-256 |
fd693867d4d49d62b0eb1f7bc22b59e2bb0c920cbdd8fdaeb976b79f1911b57b
|
Provenance
The following attestation bundles were made for ratel_ai-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on ratel-ai/ratel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ratel_ai-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
4a387bc60e0d2c091cb10b691be15a11a93f3bc658c6514b52033b8eee20e4d8 - Sigstore transparency entry: 1778033497
- Sigstore integration time:
-
Permalink:
ratel-ai/ratel@f7ba4b738afc6deb58ca2cce0522f3e6b3ee01f5 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/ratel-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f7ba4b738afc6deb58ca2cce0522f3e6b3ee01f5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ratel_ai-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: ratel_ai-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 808.5 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c7187e90de769d49dab6d6ccdd12c96cdeea243237a066bee473d52a6f16981
|
|
| MD5 |
d4fa6c81dbc99e9a162477f207807873
|
|
| BLAKE2b-256 |
dd1971f99c748ec698c767dc85b27f71a5d4c8527dfb432a07172f2c33a14275
|
Provenance
The following attestation bundles were made for ratel_ai-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on ratel-ai/ratel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ratel_ai-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
2c7187e90de769d49dab6d6ccdd12c96cdeea243237a066bee473d52a6f16981 - Sigstore transparency entry: 1778033238
- Sigstore integration time:
-
Permalink:
ratel-ai/ratel@f7ba4b738afc6deb58ca2cce0522f3e6b3ee01f5 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/ratel-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f7ba4b738afc6deb58ca2cce0522f3e6b3ee01f5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ratel_ai-0.1.6-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: ratel_ai-0.1.6-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 711.3 kB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7197484f0de96a87b321a5c8e2bbfa28ce26bf3e19bcbd122990bd81291b3219
|
|
| MD5 |
95b9fd269b8ccdfbf7e846fcf05eebb5
|
|
| BLAKE2b-256 |
c9290b4a9fb3874b311ef9b3c346aee5df0bd9a2b6de8ea3f0425601238643d8
|
Provenance
The following attestation bundles were made for ratel_ai-0.1.6-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on ratel-ai/ratel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ratel_ai-0.1.6-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
7197484f0de96a87b321a5c8e2bbfa28ce26bf3e19bcbd122990bd81291b3219 - Sigstore transparency entry: 1778033336
- Sigstore integration time:
-
Permalink:
ratel-ai/ratel@f7ba4b738afc6deb58ca2cce0522f3e6b3ee01f5 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/ratel-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f7ba4b738afc6deb58ca2cce0522f3e6b3ee01f5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ratel_ai-0.1.6-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: ratel_ai-0.1.6-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 715.0 kB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74d2be09e4fbd326cbbb03b8204cc7d0dc24bcced30259d76d11e403a1817fe9
|
|
| MD5 |
209d8f6f6a580c3e89ab67cacbaa2dfc
|
|
| BLAKE2b-256 |
eed919229435fa023a23ba4596cad4f37ff29c43ba6ddae4c64644281fb9a575
|
Provenance
The following attestation bundles were made for ratel_ai-0.1.6-cp39-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on ratel-ai/ratel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ratel_ai-0.1.6-cp39-abi3-macosx_10_12_x86_64.whl -
Subject digest:
74d2be09e4fbd326cbbb03b8204cc7d0dc24bcced30259d76d11e403a1817fe9 - Sigstore transparency entry: 1778033152
- Sigstore integration time:
-
Permalink:
ratel-ai/ratel@f7ba4b738afc6deb58ca2cce0522f3e6b3ee01f5 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/ratel-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f7ba4b738afc6deb58ca2cce0522f3e6b3ee01f5 -
Trigger Event:
push
-
Statement type: