Skip to main content

Python SDK for the Phrony runtime (gRPC).

Project description

phrony

Python client for the Phrony runtime over gRPC. Use it to run agents, open interactive sessions, and register tool workers.

This package targets Python 3.10+ and speaks the runtime API defined in runtime/proto/phrony/runtime/v1/runtime.proto. It is not the cloud HTTP control-plane client.

Install

pip install phrony

Runtime address

By default the SDK dials 127.0.0.1:7777. Override with the environment variable or options on each entrypoint:

export PHRONY_RUNTIME_ADDR=127.0.0.1:7777

Start the runtime locally (see the runtime repo) before calling the SDK.

Quick start

Run an agent

import asyncio
import os

from phrony import Phrony


async def main() -> None:
    phrony = await Phrony.connect(
        runtime_addr=os.environ.get("PHRONY_RUNTIME_ADDR", "127.0.0.1:7777"),
    )

    result = await phrony.agent("default/my-agent").run(
        input={"claimId": "CLM-48219"},
    )

    print(result.session_id, result.output)
    await phrony.close()


asyncio.run(main())

Agent references use namespace/name or namespace/name@version. Set wait=False on run() to start a session via unary RunSession and return immediately with the session id.

Register a tool worker

import asyncio
import os

from phrony.worker import Worker, ToolError


worker = Worker(
    worker_id="weather-worker-1",
    runtime_addr=os.environ.get("PHRONY_RUNTIME_ADDR", "127.0.0.1:7777"),
)


@worker.tool("weather.get-forecast", version="1.0.0", max_concurrency=4)
async def get_forecast(args: dict, ctx) -> dict:
    if not args.get("city"):
        raise ToolError("invalid_args", "city is required")
    return {"temp_c": 12, "city": args["city"]}


async def main() -> None:
    await worker.connect()  # blocks until disconnect
    await worker.close()


asyncio.run(main())

Workers connect on the bidirectional Work stream: register handlers, heartbeats, invoke/result, and graceful shutdown. Register all tools before connect(). You can also call register_tool(...) imperatively for programmatic registration.

Low-level gRPC client

For full control over unary RPCs and streams:

import asyncio

from phrony import RuntimeClient


async def main() -> None:
    client = await RuntimeClient.connect()
    version = await client.get_version()
    print(version.version)

    session = client.run_session_interactive()
    await session.start(
        agent_ref="default/my-agent",
        input={"question": "hello"},
    )

    async for event in session.events():
        if event["type"] == "session_started":
            print(event["session_id"], event["agent_version_id"])
        if event["type"] == "text_delta":
            print(event["delta"], end="", flush=True)
        if event["type"] == "approval_required":
            await session.decide_tool_approval(
                approval_id=event["approval_id"],
                approved=True,
            )
        if event["type"] == "completed":
            print(event.get("output"))

    await session.close()
    await client.close()


asyncio.run(main())

Proto bytes fields that carry JSON (input, args, payload, and similar) are handled via json_bytes and parse_json_bytes from the main export. For advanced use you can still import generated protobuf types from phrony.gen.phrony.runtime.v1.

Development

This repo is managed with uv. Prerequisites:

  • uv
  • protobuf (protoc) when regenerating stubs — e.g. brew install protobuf
uv sync
uv run python scripts/generate_proto.py   # regenerate src/phrony/gen from ../runtime/proto
uv run pytest
uv run ruff check src tests
uv run mypy
uv build

Integration tests (require a running runtime on the configured address):

PHRONY_INTEGRATION=1 uv run pytest tests/integration

From the runtime repo you can bring up a local daemon and point PHRONY_RUNTIME_ADDR at it.

Scope and limitations

  • Local dev uses insecure gRPC by default; pass channel credentials in client options when you add TLS later.
  • Agent manifests and compile/publish flows live outside this package.

License

MIT

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

phrony-0.1.0.tar.gz (39.6 kB view details)

Uploaded Source

Built Distribution

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

phrony-0.1.0-py3-none-any.whl (48.9 kB view details)

Uploaded Python 3

File details

Details for the file phrony-0.1.0.tar.gz.

File metadata

  • Download URL: phrony-0.1.0.tar.gz
  • Upload date:
  • Size: 39.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for phrony-0.1.0.tar.gz
Algorithm Hash digest
SHA256 93c152963a966af6b3f3564236368e6c8a3bfa92bde3fe400da02457bd28dee2
MD5 21d6447da1e97900371fbcbb420f497d
BLAKE2b-256 4e3280bd6d7071206489ed3787640c6d620372eb36cb000194250de6517a4aa4

See more details on using hashes here.

Provenance

The following attestation bundles were made for phrony-0.1.0.tar.gz:

Publisher: publish.yml on phrony-platform/python-sdk

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

File details

Details for the file phrony-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: phrony-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 48.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for phrony-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b9d42bb4889e07bbbcbafdca056a4123ecb520722caff68ea0d4aba3192997e
MD5 72413c04902e11966b57e2344e4a1ab4
BLAKE2b-256 b0e3ba5f7753b238d453222556e1789dbf894a170c36e77299f9dc7b71418a5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for phrony-0.1.0-py3-none-any.whl:

Publisher: publish.yml on phrony-platform/python-sdk

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

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