Python SDK for authoring Kodelet extensions
Project description
kodelet-sdk
Python SDK for authoring Kodelet extensions.
The SDK speaks Kodelet's JSON-RPC extension protocol over stdio and provides an asyncio-first API for registering tools, commands, and event handlers.
Quick start
from kodelet_sdk import BaseModel, Extension
ext = Extension(name="weather", version="0.1.0")
class WeatherInput(BaseModel):
location: str
@ext.tool("get_weather", description="Get weather", input_schema=WeatherInput)
async def get_weather(input: WeatherInput, ctx):
return {"content": f"Weather for {input.location}"}
@ext.on("session.start")
async def session_start(event, ctx):
ctx.log.info("extension started")
if __name__ == "__main__":
ext.run_sync()
Public API
Extension registration
Extension(name=None, version=None)creates an extension host.@ext.tool(name=None, description=None, input_schema=None, timeout_in_sec=None)registers a tool.@ext.command(name=None, description=None, input_schema=None, aliases=None, kind=None, timeout_in_sec=None)registers a command.@ext.on(event, priority=0, timeout_in_sec=None)registers an event handler such assession.start,tool.call, oragent.end.await ext.run()starts the async stdio runtime;ext.run_sync()is a synchronous entrypoint convenience.
Handlers may be synchronous or asynchronous. Tool handlers may return a string, which is converted to { "content": ... }, or a protocol-shaped mapping. Command handlers return { "action": "pass" }, { "action": "respond", "response": ... }, or { "action": "runAgent", "prompt": ... }.
Pydantic and Jinja2 bridge dependencies
kodelet-sdk depends on Pydantic and Jinja2 and re-exports common entry points so extensions can be self-contained:
from kodelet_sdk import BaseModel, Field, Jinja2, Pydantic, render_template
class ReviewInput(BaseModel):
target: str = Field(min_length=1)
assert render_template("Review {{ target }}", {"target": "main"}) == "Review main"
assert Jinja2.Template("Hello {{ name }}").render(name="Kodelet") == "Hello Kodelet"
assert Pydantic.TypeAdapter(int).validate_python("1") == 1
Pydantic input schemas are converted to JSON Schema during initialization and validate incoming tool/command inputs before handlers run. Commands with validation failures return {"action": "pass"} so another command route can handle the invocation.
Context helpers
Handlers receive ctx with Kodelet call metadata and helper namespaces:
ctx.storage.read_text/write_text/read_json/write_json(...)for extension data files.ctx.path.resolve_workspace_path(...)andctx.path.relative_to_workspace(...).ctx.fs.exists/read_text/write_text/list(...)for workspace file access.ctx.process.exec(...)andctx.process.spawn(...)for async process execution.ctx.env.get(...)for environment access.ctx.log.debug/info/warn/error(...)for JSON logs to stderr.ctx.ui.input/confirm/select/notify(...)for host UI reverse-RPC calls.
Testing extensions
Use create_test_harness to exercise registrations without spawning a subprocess:
from kodelet_sdk import Extension, create_test_harness
async def test_tool():
ext = Extension(name="example")
@ext.tool("echo", description="Echo", input_schema={"type": "object"})
async def echo(input, ctx):
return {"content": input["text"]}
harness = await create_test_harness(ext)
result = await harness.execute_tool({"name": "echo", "input": {"text": "hi"}})
assert result == {"content": "hi"}
Examples
Runnable example extensions live in examples/:
examples/review/kodelet-extension-reviewis a review command extension.examples/workspace/kodelet-extension-workspaceis a workspace helper/policy extension.
From a checked-out SDK repository, run an example with:
uv run -s examples/review/kodelet-extension-review
The kodelet-extension-* files are executable wrappers so Kodelet can discover and launch them directly.
Releases
Package versions are read from VERSION.txt. To publish a release, configure PyPI Trusted Publishing for the Release workflow, then update and commit VERSION.txt manually:
git add VERSION.txt pyproject.toml uv.lock
git commit -m "chore: release v0.1.0"
make release
Pushing the vX.Y.Z tag runs the GitHub Actions release workflow, builds the package, and publishes to PyPI using OIDC trusted publishing.
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 kodelet_sdk-0.1.0.tar.gz.
File metadata
- Download URL: kodelet_sdk-0.1.0.tar.gz
- Upload date:
- Size: 55.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e1af29b4bc6496ee9dcf5f92591b6da0c5b7ca27bb3a42510686e291094e95f
|
|
| MD5 |
ef5989afd24b623f2d76b3b34174989a
|
|
| BLAKE2b-256 |
2274ab335292db1fed8c0e9c21936c46acbe383c04487a625028549fade1ce5b
|
Provenance
The following attestation bundles were made for kodelet_sdk-0.1.0.tar.gz:
Publisher:
release.yml on jingkaihe/kodelet-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kodelet_sdk-0.1.0.tar.gz -
Subject digest:
0e1af29b4bc6496ee9dcf5f92591b6da0c5b7ca27bb3a42510686e291094e95f - Sigstore transparency entry: 1698159143
- Sigstore integration time:
-
Permalink:
jingkaihe/kodelet-python-sdk@c807c77da8aeec2e8156ca903f1dfa7ac89927ec -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/jingkaihe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c807c77da8aeec2e8156ca903f1dfa7ac89927ec -
Trigger Event:
push
-
Statement type:
File details
Details for the file kodelet_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kodelet_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a90c4816a9bc4d1bad08ea941ca5c656679619be49fcfcccca07691d8d7ee979
|
|
| MD5 |
88054590eec7a30f66db52d8eb736a08
|
|
| BLAKE2b-256 |
63a4cb74f583d3f44edbabd8bfd4bcf9ab18bfd8d743b5cc9add6e7f83d3350a
|
Provenance
The following attestation bundles were made for kodelet_sdk-0.1.0-py3-none-any.whl:
Publisher:
release.yml on jingkaihe/kodelet-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kodelet_sdk-0.1.0-py3-none-any.whl -
Subject digest:
a90c4816a9bc4d1bad08ea941ca5c656679619be49fcfcccca07691d8d7ee979 - Sigstore transparency entry: 1698159202
- Sigstore integration time:
-
Permalink:
jingkaihe/kodelet-python-sdk@c807c77da8aeec2e8156ca903f1dfa7ac89927ec -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/jingkaihe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c807c77da8aeec2e8156ca903f1dfa7ac89927ec -
Trigger Event:
push
-
Statement type: