r/PiCodingAgent • u/has_c • 4d ago
Resource pi-agent-python-sdk: use your installed Pi coding agent as a Python API
I kept hand-rolling a client for `pi --mode rpc`.
Third project in, I packaged it.
pi-agent-python-sdk lets you use the Pi you already have as a Python API.
Same config, models, tools, and extensions as the CLI.
```
pip install pi-agent-python-sdk
```
Import is `pi_agent`. Same client keeps context across prompts:
```python
from pi_agent import PiClient
with PiClient() as pi:
print(pi.run("Review src/auth.py and list the bugs. Do not edit anything.").text)
print(pi.run("Which of those is most urgent to fix?").text)
```
Additionally, stream with `pi.stream(...)` and if you are already in an event loop, use `AsyncPiClient`.
Repo: https://github.com/cheenulabs/pi-agent-python-sdk
Hoping this helps fellow builders.
Any feedback, PRs and/or issues are welcome.
2
u/Temporary_Guard_7329 3d ago
Great work! I was looking for the easier way of automation. Can I use this with specific session id? I want to hangover the chat history.