Skip to main content

pi-server

Experimental. This package is under active development and may change or be removed without notice. Its APIs and behavior are not yet stable.

Server package for pi.

Session server core

The package exports the PiServer session server.

from typing import Any

from pi_server import CreateSessionOptions, PiServerService
from pi_server.transports.unix import UnixServerOptions, create_unix_server


class Service(PiServerService):
    async def list_sessions(self) -> list[dict[str, Any]]:
        return []

    async def list_models(self) -> list[dict[str, Any]]:
        return []

    async def create_session(self, options: CreateSessionOptions):
        raise NotImplementedError

    async def open_session(self, session_id: str):
        raise NotImplementedError


async def main() -> None:
    service = Service()
    server = create_unix_server(service, UnixServerOptions(path=".scratch/pi-server.sock"))
    await server.start()

PiServer composes transport listeners through the PiServerListener protocol. Each listener must complete any transport-specific authentication and authorization before passing a connection to PiServer. For example, a WebSocket listener can validate credentials during the HTTP upgrade, while the Unix listener relies on socket filesystem permissions. The Unix submodule exports the create_unix_listener() building block and create_unix_server() preset, keeping the common case concise without coupling the primary server to Unix sockets. The listener uses length-prefixed CBOR messages from pi_protocol.

This package does not provide a standalone CLI or coding-agent service. Applications supply the PiServerService implementation.

PiServerService.list_sessions() returns protocol SessionMetadata, not acquired runtime state. Services should map the durable fields their storage supports and may omit updatedAt, parentSessionId, sessionName, and cwd. PiServer refreshes available metadata from live snapshots without requiring stored sessions to fabricate phase, model, thinking-level, attachment, or lock values.

The real coding-agent service boundary lives in pi_coding_agent.core.agent_session_runtime. pi_server itself does not depend on pi_coding_agent.

Transport testing

Custom transports can use pi_server.testing for deterministic protocol conformance tests. It exports create_test_server(), TestServerService, TestSessionRuntime, ProtocolTestClient, and the transport-neutral WireChannel contract. connect_unix_test_client() is provided for Unix transport tests.

from pi_server import PiServerOptions
from pi_server.testing import TestServerService, create_test_server


async def main() -> None:
    service = TestServerService()
    harness = create_test_server(PiServerOptions(listeners=[]), service)
    await harness.server.start()
    await harness.server.close()

pi-ai protocol bridge

pi_ai domain objects and pi_protocol wire DTOs remain independent. This package owns their boundary and exports to_protocol_model_metadata(), to_protocol_assistant_message(), to_protocol_user_message(), and to_protocol_tool_result_message().

The adapters reject invalid tool inputs, identifiers, timestamps, and mismatched tool results; to_protocol_tool_result_message() requires the original ToolCall so it can verify the association and convert its arguments itself. Diagnostic details are explicitly sanitized. Closed pi_ai unions are mapped exhaustively. The protocol mirrors pi_ai vocabulary such as toolCall and toolUse where the semantics are identical. Protocol schemas enforce consistent lifecycle states, and tests encode adapter output through the runtime schemas so incompatible changes fail in the bridging package.

Development

From the repository root:

uv sync --all-packages
uv run pytest packages/pi-server
uv run ruff check packages/pi-server

pp-rpc-server is developed in HSPK/pp_rpc_server. It was split out of the pp monorepo; sibling packages (pp-ai, pp-agent-core, pp-tui, pp-coding-agent, ...) each live in their own repository and are consumed from PyPI.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pp_rpc_server-0.2.1.tar.gz (52.6 kB view details)

Uploaded Source

Built Distribution

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

pp_rpc_server-0.2.1-py3-none-any.whl (32.4 kB view details)

Uploaded Python 3

File details

Details for the file pp_rpc_server-0.2.1.tar.gz.

File metadata

  • Download URL: pp_rpc_server-0.2.1.tar.gz
  • Upload date:
  • Size: 52.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pp_rpc_server-0.2.1.tar.gz
Algorithm Hash digest
SHA256 82eb8cffa88d14efede6660ab92b6692ce29640076bd1e9e319aedd392cd971c
MD5 61f8d61f91fc27025c60ac79dfc78dd5
BLAKE2b-256 8693f3f0b93e05bd112f362dbbbc705e696b7e9e91e91b05d510a40f0836f0dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pp_rpc_server-0.2.1.tar.gz:

Publisher: release.yml on HSPK/pp_rpc_server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pp_rpc_server-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pp_rpc_server-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 32.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pp_rpc_server-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 377f0c199f2797c6d657210b0d2e9056639000dfe656e39924be2f7b94aa5199
MD5 90c96c8193508128bc995a258d57dd10
BLAKE2b-256 f946174613743a61d738c79a214c51e07c0890b18aa2bda8fcf03a85fcb0ca71

See more details on using hashes here.

Provenance

The following attestation bundles were made for pp_rpc_server-0.2.1-py3-none-any.whl:

Publisher: release.yml on HSPK/pp_rpc_server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.0

2 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