Skip to main content

Python SDK facade for Pi Coding Agent sessions, services, resources, tools, and extensions

Project description

Pi Coding Agent Python SDK

Python facade for creating Pi Coding Agent sessions, wiring resources, running the bundled TypeScript bridge, exposing MCP servers, and serving the agent through ACP.

The package published to PyPI is pi-coding-agent-python-sdk. The import package is pi_coding_agent.

Install

pip install pi-coding-agent-python-sdk

ACP support is optional:

pip install "pi-coding-agent-python-sdk[acp]"

Provider-backed sessions use the bundled bridge worker and require either Node.js or Bun on PATH. The explicit backend="in_process" mode is a local deterministic mode for tests and offline examples.

Quick Start

import asyncio

from pi_coding_agent import MessageUpdateEvent, create_agent_session


async def main() -> None:
    result = await create_agent_session(cwd=".", backend="in_process")
    session = result.session
    try:
        session.subscribe(
            lambda event: print(event.assistant_message_event.delta, end="")
            if isinstance(event, MessageUpdateEvent)
            else None
        )
        await session.prompt("List the files in this directory.")
    finally:
        await session.dispose()


asyncio.run(main())

This first example is a local smoke test. For a provider-backed session, use HarnessConfig and keep secrets in environment variables:

import asyncio

from pi_coding_agent import HarnessConfig, create_agent_session_from_config


config = HarnessConfig.from_dict(
    {
        "run": {"cwd": ".", "backend": "node"},
        "env": {
            "required": ["NOVITA_API_KEY"],
            "optional": ["NOVITA_BASE_URL"],
        },
        "model": {
            "provider": "novita",
            "id": "deepseek/deepseek-v4-flash",
            "base_url": "https://api.novita.ai/v3/openai",
            "api_key_env": "NOVITA_API_KEY",
            "context_window": 128000,
            "max_tokens": 32000,
            "reasoning": True,
            "compat": {
                "thinkingFormat": "deepseek",
                "requiresReasoningContentOnAssistantMessages": True,
            },
        },
        "provider_options": {
            "temperature": 0,
            "tool_choice": "auto",
            "parallel_tool_calls": True,
        },
        "tools": {"allow": ["read", "write", "edit", "bash", "grep", "find", "ls"]},
    }
)


async def main() -> None:
    result = await create_agent_session_from_config(config)
    try:
        await result.session.prompt("Inspect the project and summarize the test layout.")
    finally:
        await result.session.dispose()


asyncio.run(main())

Harness TOML

HarnessConfig can load and dump TOML. It covers runtime selection, model/provider setup, environment passthrough, tool allowlists, resources, extensions, skills, MCP servers, hooks, and session storage.

version = 1

[run]
cwd = "."
backend = "node"

[js]
runtime = "bun"
request_timeout_sec = 30
tool_timeout_sec = 60
compact_timeout_sec = 300

[env]
required = ["NOVITA_API_KEY"]
optional = ["NOVITA_BASE_URL"]

[model]
provider = "novita"
id = "deepseek/deepseek-v4-flash"
base_url = "https://api.novita.ai/v3/openai"
api_key_env = "NOVITA_API_KEY"
context_window = 128000
max_tokens = 32000
reasoning = true

[model.compat]
thinkingFormat = "deepseek"
requiresReasoningContentOnAssistantMessages = true

[provider_options]
temperature = 0
tool_choice = "auto"
parallel_tool_calls = true

[tools]
allow = ["read", "write", "edit", "bash", "grep", "find", "ls"]

[mcp.servers.time]
command = "uvx"
args = ["mcp-server-time"]
import asyncio

from pi_coding_agent import create_agent_session_from_config


async def main() -> None:
    result = await create_agent_session_from_config("pi-harness.toml")
    try:
        await result.session.prompt("What time tools are available?")
    finally:
        await result.session.dispose()


asyncio.run(main())

Main Capabilities

  • Session creation through create_agent_session, create_agent_session_from_config, create_agent_session_services, and create_agent_session_runtime.
  • Built-in tools: read, write, edit, bash, grep, find, and ls.
  • Python custom tools through ToolDefinition.
  • TypeScript extension paths, package extension sources, and Python extension factories.
  • Skills from local paths, GitHub sources through npx skills add, and Pi package-loader sources.
  • Prompt templates, AGENTS.md discovery, system prompt overrides, and append-system-prompt files.
  • MCP server configuration through McpConfig or TOML.
  • Hooks for session, prompt, tool, compact, and stop events.
  • Session JSON serialization and restoration.
  • ACP server integration through pi-coding-agent-acp.

Documentation

Development

Run the default suite with uv:

uv run -m unittest discover -s tests

Build and inspect the package:

uv build
uv run --with twine python -m twine check dist/*

The test suite is designed to run without provider credentials by default. Provider-backed tests are opt-in and should use environment variables, not checked-in secrets.

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

pi_coding_agent_python_sdk-0.1.1.tar.gz (8.0 MB view details)

Uploaded Source

Built Distribution

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

pi_coding_agent_python_sdk-0.1.1-py3-none-any.whl (8.5 MB view details)

Uploaded Python 3

File details

Details for the file pi_coding_agent_python_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: pi_coding_agent_python_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 8.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pi_coding_agent_python_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c04ee3529caa8a61bca4b23ba2e0a09701126af25f62e9a34ea2bac4a6c886de
MD5 9cf6b52e7ab94e2567c4aa8384e8a21a
BLAKE2b-256 cdb8b2d9c51853fa3c572ad854a98817fba610b5453d706f640be8e575dddedc

See more details on using hashes here.

File details

Details for the file pi_coding_agent_python_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pi_coding_agent_python_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pi_coding_agent_python_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 edaef5b5952b07a67997343e9b66a9efde47a3d6c4c266b7b02798fb919bd79d
MD5 a2705c1ea8550f3f81a90595e62830f1
BLAKE2b-256 2b649d4f994a7769b9697db285f5e023aa8c37f1cc9ee55ef6053e15a36c9e46

See more details on using hashes here.

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