PiEx
Elixir client for the Pi coding agent RPC
protocol. Spawns a pi --mode rpc process and communicates over
JSON-over-stdin/stdout. Zero runtime dependencies - uses only Elixir 1.18+
built-in JSON module.
Installation
Add pi_ex to your list of dependencies in mix.exs:
def deps do
[
{:pi_ex, "~> 0.1.0"}
]
endQuick start
# Start an instance (requires `pi` on PATH)
{:ok, pid} = PiEx.Instance.start_link([])
# Send a prompt
:ok = PiEx.prompt(pid, "Hello!")
# Receive streamed events
receive do
{:pi_event, _, %PiEx.Event.MessageUpdate{type: :text_delta, text: text}} ->
IO.write(text)
endAccumulating responses
Use PiEx.Delta to collect a full response from the event stream:
delta = PiEx.Delta.new()
delta =
receive do
{:pi_event, _, event} -> PiEx.Delta.apply_event(delta, event)
end
PiEx.Delta.text(delta) # accumulated response text
PiEx.Delta.thinking(delta) # accumulated reasoning
PiEx.Delta.done?(delta) # true when stream is completeExamples
Self-contained scripts under examples/ can be run directly:
elixir examples/simple_prompt.exs "What is 2+2?"
elixir examples/streaming.exs "Write a haiku"
elixir examples/chat.exs
# Use a different binary
PI_PATH=/path/to/bin elixir examples/chat.exsLicense
MIT - see LICENSE.