Skip to main content

DotCode SDK — Python

Embed the DotCode coding agent in your application and drive it with any LLM (Anthropic, OpenAI, Azure OpenAI, Gemini, DeepSeek, Ollama, OpenAI-compatible). The SDK talks JSON-RPC to a dotcode serve process.

Built by Gravicode Studios, led by Kang Fadhil. · 🇮🇩 Dokumentasi Bahasa Indonesia: docs/id/sdk.md

Install

pip install dotcode-sdk

The SDK needs the dotcode CLI: put it on PATH or set DOTCODE_CLI_PATH (a path to dotcode.dll is started with dotnet). Configure providers with environment variables (ANTHROPIC_API_KEY, OPENAI_API_KEY, DEEPSEEK_API_KEY, …), ~/.dotcode/settings.json, or per session with the typed providers option.

Usage

import asyncio
from dataclasses import dataclass
from typing import Annotated
from dotcode_sdk import DotCodeClient, PermissionHandler, ToolCompletedEvent, AssistantTextDeltaEvent, define_tool

@dataclass
class WeatherParams:                       # parameters are a class, never a hand-written JSON schema
    city: Annotated[str, "City name"]

@define_tool(description="Weather for a city")
async def get_weather(params: WeatherParams) -> str:
    return f"{params.city}: 24°C"          # a typo like params.cty is flagged by mypy/pyright

async def main():
    async with DotCodeClient() as client:  # spawns `dotcode serve`
        async with await client.create_session(
            model="deepseek:deepseek-v4-flash",
            tools=[get_weather],
            on_permission_request=PermissionHandler.approve_all,
        ) as session:
            session.on(AssistantTextDeltaEvent, lambda e: print(e.text, end=""))
            session.on(ToolCompletedEvent, lambda e: print(f"
✔ {e.name}: {e.summary}"))
            result = await session.send_and_wait("What's the weather in Bogor?")
            print(result.cost_usd)

asyncio.run(main())

Parameter classes can be @dataclasses, TypedDicts or pydantic models (pip install dotcode-sdk[pydantic]). Arguments are validated and converted before your handler runs; mismatches are reported back to the model. Options, events (match event: case ToolCompletedEvent(name=n): ...), permission decisions, built-in tool names (BuiltinTool.READ, BuiltinTool.BASH.rule("npm test:*")) and providers (ProviderConfig(type="ollama")) are all typed, and the package ships py.typed.

API

DotCodeClient start(), create_session(...), resume_session(id, fork=..., ...), list_sessions(), list_models(), ping(), stop(), force_stop()
DotCodeSession send(prompt) (returns once dispatched), send_and_wait(prompt, timeout=), stream(prompt), on(handler) / on(EventClass, handler), abort(), set_model(), set_permission_mode(), set_reasoning_effort(), compact(), clear(), get_messages(), list_tools(), disconnect()
Tools @define_tool(description=..., read_only=...); handlers take (params), (params, invocation), (invocation) or nothing and return a string, a ToolResult or any JSON value
Permissions PermissionHandler.approve_all / reject_all, or return PermissionDecisionApproveOnce(), PermissionDecisionApproveForSession(), PermissionDecisionApproveAlways(rule), PermissionDecisionReject(feedback); sessions are deny-by-default without a handler
Other handlers on_user_input_request (AskUserQuestion), on_exit_plan_mode (plan review), on_event
Options model, fallback_model, working_directory, permission_mode, reasoning_effort, system_message, available_tools, allowed_tools, excluded_tools, mcp_servers (McpStdioServer / McpHttpServer), providers (BYOK), max_turns, persist_session, worktree, disable_mcp

Full guide: docs/en/sdk.md · Protocol: schema/protocol.schema.json

License: MIT

Metadata

Release files for dotcode-sdk 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dotcode-sdk 0.2.0
File Size Uploaded
dotcode_sdk-0.2.0.tar.gz 23.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dotcode-sdk 0.2.0
File Interpreter ABI Platform
dotcode_sdk-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 45.9 kB

Release files / dotcode_sdk-0.2.0.tar.gz

Download URL dotcode_sdk-0.2.0.tar.gz
Size 23.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8455d561dd5a1c66aec2754add1aacb0334e4fb0079d64acfd417d6f3003db92
BLAKE2b-256 checksum
How to use checksums
87cf1902483b57bca2a82508bed12881097370837f0c604ca5b49da6d6aaa629
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / dotcode_sdk-0.2.0-py3-none-any.whl

Download URL dotcode_sdk-0.2.0-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06847ba7707215affed056a92634498a802003bba080b51e023ff09e56b2190c
BLAKE2b-256 checksum
How to use checksums
d56506601c57e8692bcb8ed9e78902fd8f5b48abe6869f87546f63ea5648274d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page