Skip to main content

Zero-copy Agent Protocol (ZAP) SDK - 1000x faster than MCP

Project description

hanzo-zap

Zero-copy Agent Protocol (ZAP) SDK for Python.

1000x faster than MCP/JSON-RPC through binary wire protocol with zero-copy serialization.

Installation

pip install hanzo-zap
# or
uv add hanzo-zap

Quick Start

Client

import asyncio
from hanzo_zap import ZapClient

async def main():
    # Connect to a ZAP server
    async with ZapClient.connect("zap://localhost:9999") as client:
        # List available tools
        tools = await client.list_tools()
        print("Tools:", [t.name for t in tools])

        # Call a tool
        result = await client.call_tool("read_file", {"path": "README.md"})
        print("Content:", result.content)

        # Batch multiple calls
        results = await client.batch([
            {"name": "read_file", "args": {"path": "package.json"}},
            {"name": "git_status", "args": {}},
        ])

asyncio.run(main())

Server

import asyncio
from hanzo_zap import ZapServer

server = ZapServer(name="my-tools", version="1.0.0")

@server.tool("greet", "Greet someone by name", {"type": "object", "properties": {"name": {"type": "string"}}})
async def greet(name: str, args: dict) -> str:
    return f"Hello, {args['name']}!"

asyncio.run(server.serve(9999))

Wire Protocol

ZAP uses a simple length-prefixed binary format:

+----------+----------+------------------+
| Length   | MsgType  | Payload          |
| (4 bytes)| (1 byte) | (variable)       |
| LE u32   |          | JSON             |
+----------+----------+------------------+

API

ZapClient

  • ZapClient.connect(url) - Connect to server
  • client.list_tools() - List available tools
  • client.call_tool(name, args) - Call a tool
  • client.batch(calls) - Call multiple tools
  • client.ping() - Check connection
  • client.close() - Close connection

ZapServer

  • ZapServer(name, version) - Create server
  • server.register_tool(name, description, schema, handler) - Register tool
  • @server.tool(name, description, schema) - Decorator to register tool
  • server.serve(port) - Start serving (blocking)
  • server.start(port) - Start in background
  • server.stop() - Stop server

Policies

from hanzo_zap import ApprovalPolicy, SandboxPolicy

# Approval policies (when to ask for human approval)
ApprovalPolicy.UNLESS_TRUSTED  # Only auto-approve known-safe reads
ApprovalPolicy.ON_FAILURE      # Auto-approve, escalate on failure
ApprovalPolicy.ON_REQUEST      # Model decides (default)
ApprovalPolicy.NEVER           # Never ask

# Sandbox policies
sandbox = SandboxPolicy.workspace_write(
    writable_roots=["/home/user/project"],
    network_access=True,
)

License

MIT - Hanzo AI Inc.

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

hanzo_zap-0.6.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

hanzo_zap-0.6.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file hanzo_zap-0.6.0.tar.gz.

File metadata

  • Download URL: hanzo_zap-0.6.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for hanzo_zap-0.6.0.tar.gz
Algorithm Hash digest
SHA256 55609ea205709a35ce62a65a107ea86dc1c11d5c69ba54b162d0712011602211
MD5 5a002b95f9077cbaa7c13647cc57f88e
BLAKE2b-256 efb211d813f51274999e76090ab24b890b3c2e7675ece2fcf6d41a0887d3b109

See more details on using hashes here.

File details

Details for the file hanzo_zap-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: hanzo_zap-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for hanzo_zap-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e62c4d3746988d2f0b3d96bc7b327e08a655099335f0a313e3853374ab31e36f
MD5 2988da51f437b269bc095ef94dc06a79
BLAKE2b-256 b336fc29cdb989bfef52082f5c77f02e38dffe93569f8eb3aa48668bdf2e0b0e

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