Skip to main content

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 zag CLI binary installed and on your PATH (or set via ZAG_BIN env 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

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

zag_agent-0.5.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

zag_agent-0.5.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file zag_agent-0.5.0.tar.gz.

File metadata

  • Download URL: zag_agent-0.5.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

Hashes for zag_agent-0.5.0.tar.gz
Algorithm Hash digest
SHA256 a2a7cc4f9944a35bc05a05993061dcea479165acf15978e48784fd79a7e851e0
MD5 61ac65650be40a55bd8166281719ea6e
BLAKE2b-256 f899d7635491923ebff3d9377299acc9006ac93e4a87113fdcd469a33983c20b

See more details on using hashes here.

File details

Details for the file zag_agent-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: zag_agent-0.5.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

Hashes for zag_agent-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d70fef5d49945aa281359a72fde38ec758a6ce07b9076814dc955251500b81a4
MD5 8a58a6ce97bc8fe44a7b0633e58730ab
BLAKE2b-256 41071651207bd75ab39741d5f8d08c241e143144385d7b03752478005062e6ad

See more details on using hashes here.

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