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 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file phrony-0.0.1.tar.gz.
File metadata
- Download URL: phrony-0.0.1.tar.gz
- Upload date:
- Size: 39.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8e5d92bb03186f6a6dfa0dcd654bb0436227ae87b6ffbe95e693b9d4232ca72
|
|
| MD5 |
70088dd8e016a8a1e37b2ba586d4e044
|
|
| BLAKE2b-256 |
063790d43096bac1dfd36fb6360c707b447396d848292160d38562e62c6ffcd9
|
Provenance
The following attestation bundles were made for phrony-0.0.1.tar.gz:
Publisher:
publish.yml on phrony-platform/python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
phrony-0.0.1.tar.gz -
Subject digest:
c8e5d92bb03186f6a6dfa0dcd654bb0436227ae87b6ffbe95e693b9d4232ca72 - Sigstore transparency entry: 2191764406
- Sigstore integration time:
-
Permalink:
phrony-platform/python-sdk@c4d5f90c34dcb20474d07f34e8f31ffb184ac38e -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/phrony-platform
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c4d5f90c34dcb20474d07f34e8f31ffb184ac38e -
Trigger Event:
release
-
Statement type:
File details
Details for the file phrony-0.0.1-py3-none-any.whl.
File metadata
- Download URL: phrony-0.0.1-py3-none-any.whl
- Upload date:
- Size: 49.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
447d25e5a55b70567cc087318a859bfa9b8f23ce3611d0e1086e7e22b12cb686
|
|
| MD5 |
b7c4ee236e719d2853737fb9e694a63a
|
|
| BLAKE2b-256 |
201212300f5f670d7eb2fc6e7d0bcd2436077837f898a7f05189ff7d6e59477b
|
Provenance
The following attestation bundles were made for phrony-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on phrony-platform/python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
phrony-0.0.1-py3-none-any.whl -
Subject digest:
447d25e5a55b70567cc087318a859bfa9b8f23ce3611d0e1086e7e22b12cb686 - Sigstore transparency entry: 2191764424
- Sigstore integration time:
-
Permalink:
phrony-platform/python-sdk@c4d5f90c34dcb20474d07f34e8f31ffb184ac38e -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/phrony-platform
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c4d5f90c34dcb20474d07f34e8f31ffb184ac38e -
Trigger Event:
release
-
Statement type: