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.3.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.3.0
File Size Uploaded Provenance Actions
dotcode_sdk-0.3.0.tar.gz 26.3 kB Without provenance Details for dotcode_sdk-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 52.1 kB

Release files / dotcode_sdk-0.3.0.tar.gz

Download URL dotcode_sdk-0.3.0.tar.gz
Size 26.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9ea28ae7f8488b5deb68a3f6414ac44a9380f16110da0792ed2166f5ebd87583
BLAKE2b-256 checksum
How to use checksums
1924d1c909b394164aef9163d694e6406acffff619b9e441727d009788910128
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.3.0-py3-none-any.whl

Download URL dotcode_sdk-0.3.0-py3-none-any.whl
Size 25.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5dcc7e245007bc881685cf0f6049b39531c64eb7989ba306a816c22ef7b53001
BLAKE2b-256 checksum
How to use checksums
7a1cd2cebab91db66176673edfe6a95cf7219798472d15d73a6c4b9ed16fe436
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for dotcode-sdk 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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