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.2.4.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.2.4-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zag_agent-0.2.4.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.2.4.tar.gz
Algorithm Hash digest
SHA256 b4d4b01a89ecd6b8c2190d8dca7244ec0336c8df3ee5d0c9fbac0180b3163c12
MD5 918863b0c3a27c72634d55979711a166
BLAKE2b-256 e54d446114592c227f9b1e105a995bfb30a7a3e2f7ea45b8e0491d5a0d85eb36

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zag_agent-0.2.4-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.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0d83999fcb287012098f12f6296063ebd08bf2d0e5d8c198a4249349e2b957ad
MD5 a498f2287854e5f9e735f8f83993bd37
BLAKE2b-256 3b24a432ea96aa32dfc4932715c83a3d67c6e934499d4deb54c5c29cd00b34dc

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