Python SDK for zag — a unified CLI for AI coding agents
Project description
Zag Python Binding
Python binding for zag — a unified CLI for AI coding agents.
Prerequisites
- Python 3.10+
- The
zagCLI binary installed and on yourPATH(or set viaZAG_BINenv var)
Installation
pip install zag-agent
For development from source:
cd bindings/python
pip install -e .
Quick start
from zag import ZagBuilder
output = await ZagBuilder() \
.provider("claude") \
.model("sonnet") \
.auto_approve() \
.exec("write a hello world program")
print(output.result)
Streaming
from zag import ZagBuilder
async for event in await ZagBuilder().provider("claude").stream("analyze code"):
print(event.type, event)
Builder methods
| Method | Description |
|---|---|
.provider(name) |
Set provider: "claude", "codex", "gemini", "copilot", "ollama" |
.model(name) |
Set model name or size alias ("small", "medium", "large") |
.system_prompt(text) |
Set a system prompt |
.root(path) |
Set the working directory |
.auto_approve() |
Skip permission prompts |
.add_dir(path) |
Add an additional directory (chainable) |
.json_mode() |
Request JSON output |
.json_schema(schema) |
Validate output against a JSON schema (implies .json_mode()) |
.json_stream() |
Enable streaming NDJSON output |
.worktree(name=None) |
Run in an isolated git worktree |
.sandbox(name=None) |
Run in a Docker sandbox |
.session_id(uuid) |
Use a specific session ID |
.output_format(fmt) |
Set output format ("text", "json", "json-pretty", "stream-json") |
.input_format(fmt) |
Set input format ("text", "stream-json" — Claude only) |
.replay_user_messages() |
Re-emit user messages on stdout (Claude only) |
.include_partial_messages() |
Include partial message chunks (Claude only) |
.max_turns(n) |
Set the maximum number of agentic turns |
.show_usage() |
Show token usage statistics (JSON output mode) |
.size(size) |
Set Ollama model parameter size (e.g., "2b", "9b", "35b") |
.verbose() |
Enable verbose output |
.quiet() |
Suppress non-essential output |
.debug() |
Enable debug logging |
.bin(path) |
Override the zag binary path |
Terminal methods
| Method | Returns | Description |
|---|---|---|
.exec(prompt) |
AgentOutput |
Run non-interactively, return structured output |
.stream(prompt) |
AsyncGenerator[Event] |
Stream NDJSON events |
.exec_streaming(prompt) |
StreamingSession |
Bidirectional streaming (Claude only) |
.run(prompt=None) |
None |
Start an interactive session (inherits stdio) |
.resume(session_id) |
None |
Resume a previous session by ID |
.continue_last() |
None |
Resume the most recent session |
How it works
The SDK spawns the zag CLI as a subprocess (zag exec -o json or -o stream-json) and parses the JSON/NDJSON output into typed dataclasses. Zero external dependencies — only the Python standard library.
Testing
pip install pytest pytest-asyncio
pytest
See also
License
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 zag_agent-0.3.0.tar.gz.
File metadata
- Download URL: zag_agent-0.3.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7450e7369fc13faef3b57f4e85c600d7fb4d157bb1ccf4ff56277978bae77e38
|
|
| MD5 |
9ef45c5d47b27d8b4a239b1bdd076485
|
|
| BLAKE2b-256 |
6deca39f65de3a4eb79558c309d9290cf78d79e997ae33f0dec6feb91b890bee
|
File details
Details for the file zag_agent-0.3.0-py3-none-any.whl.
File metadata
- Download URL: zag_agent-0.3.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26bf00ed8dac6bd855ffbaaa6a7b6a9dc7fcd4b67aa82812ebdb83131fd4ae11
|
|
| MD5 |
818d0a158e3f73ca5d34d49cbe45f360
|
|
| BLAKE2b-256 |
c00f1e3d7162fc6f5d964fd47aea7762205c1d6a27f137e03b76b92ad31b236c
|