ZAP - Zero-Copy Application Protocol for AI agent communication
Project description
zap-schema
ZAP - Zero-Copy App Proto for Python
High-performance Cap'n Proto RPC for AI agent communication.
Installation
pip install zap-schema
# With uv (recommended)
uv pip install zap-schema
Quick Start
import asyncio
from zap_schema import Client
async def main():
# Connect to a ZAP gateway
client = await Client.connect("zap://localhost:9999")
# List available tools
tools = await client.list_tools()
print(f"Available tools: {tools}")
# Call a tool
result = await client.call_tool("search", {
"query": "machine learning"
})
print(f"Result: {result}")
# Read a resource
content = await client.read_resource("file:///data/config.json")
print(f"Content: {content}")
# List prompts
prompts = await client.list_prompts()
print(f"Prompts: {prompts}")
# Get a specific prompt
messages = await client.get_prompt("code-review", {
"file": "main.py"
})
print(f"Messages: {messages}")
asyncio.run(main())
Features
- Zero-copy serialization via Cap'n Proto
- Async/await native with asyncio
- Multi-transport - TCP, Unix socket, WebSocket, HTTP/SSE
- MCP compatible - Works with Model Context Protocol servers
- Post-quantum cryptography with ML-KEM and ML-DSA
- W3C DID identity for decentralized agent authentication
- Agentic consensus for trustless response voting
Client API
Connection
from zap_schema import Client
# TCP connection (default)
client = await Client.connect("zap://localhost:9999")
# Unix socket
client = await Client.connect("unix:///var/run/zap.sock")
# WebSocket
client = await Client.connect("ws://localhost:9999/ws")
# HTTP/SSE
client = await Client.connect("http://localhost:8080/mcp")
Tools
# List all available tools
tools = await client.list_tools()
for tool in tools:
print(f"{tool.name}: {tool.description}")
# Call a tool with arguments
result = await client.call_tool("search", {
"query": "hello world",
"limit": 10
})
# Handle tool result
if result.is_error:
print(f"Error: {result.error}")
else:
print(f"Content: {result.content}")
Resources
# List all resources
resources = await client.list_resources()
for resource in resources:
print(f"{resource.uri}: {resource.name}")
# Read a resource
content = await client.read_resource("file:///data/config.json")
print(content.text) # or content.blob for binary
# Subscribe to resource updates
async for update in client.subscribe_resource("file:///data/live.json"):
print(f"Updated: {update}")
Prompts
# List prompts
prompts = await client.list_prompts()
for prompt in prompts:
print(f"{prompt.name}: {prompt.description}")
# Get prompt with arguments
messages = await client.get_prompt("code-review", {
"language": "python",
"file": "main.py"
})
for msg in messages:
print(f"{msg.role}: {msg.content}")
Gateway
Run a ZAP gateway that aggregates multiple MCP servers:
from zap_schema import Gateway
gateway = Gateway(host="0.0.0.0", port=9999)
# Add MCP servers
gateway.add_server("filesystem", "stdio://npx @modelcontextprotocol/server-filesystem /data")
gateway.add_server("database", "http://localhost:8080/mcp")
gateway.add_server("search", "ws://localhost:9000/ws")
# Start gateway
await gateway.start()
Post-Quantum Cryptography
from zap_schema.crypto import MLKem, MLDsa
# Key encapsulation (ML-KEM-768)
public_key, secret_key = MLKem.generate_keypair()
ciphertext, shared_secret = MLKem.encapsulate(public_key)
decrypted_secret = MLKem.decapsulate(ciphertext, secret_key)
# Digital signatures (ML-DSA-65)
public_key, secret_key = MLDsa.generate_keypair()
signature = MLDsa.sign(message, secret_key)
is_valid = MLDsa.verify(message, signature, public_key)
Decentralized Identity
from zap_schema.identity import NodeIdentity, Did
# Generate node identity
identity = NodeIdentity.generate()
print(f"DID: {identity.did}")
# Create DID from existing key
did = Did.from_mldsa_key(public_key)
print(f"DID: {did}") # did:key:z6Mk...
# Sign and verify
signature = identity.sign(b"message")
is_valid = identity.verify(b"message", signature)
Agent Consensus
from zap_schema.consensus import AgentConsensus
# Create consensus with 67% threshold
consensus = AgentConsensus(threshold=0.67)
# Submit responses from multiple agents
await consensus.submit_response(agent_a_did, response_a)
await consensus.submit_response(agent_b_did, response_b)
await consensus.submit_response(agent_c_did, response_c)
# Get consensus result
result = await consensus.finalize()
if result.reached:
print(f"Consensus: {result.response}")
else:
print(f"No consensus reached")
Development
# Clone the repository
git clone https://github.com/zap-protocol/zap
cd zap/python
# Create virtual environment
uv venv
uv pip install -e ".[dev]"
# Run tests
uv run pytest tests/ -v
# Run tests with coverage
uv run pytest tests/ -v --cov=src/zap_schema --cov-report=term
# Type checking
uv run mypy src
# Linting
uv run ruff check src
Links
License
MIT
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
zap_schema-1.0.0.tar.gz
(57.2 kB
view details)
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 zap_schema-1.0.0.tar.gz.
File metadata
- Download URL: zap_schema-1.0.0.tar.gz
- Upload date:
- Size: 57.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
451b1ce05b6ae9c1b016e86fdbc04d62a78a0d720a970a7e61b0579954fb687d
|
|
| MD5 |
a462b5f1ae1cc26fb4c0538459b4c1ce
|
|
| BLAKE2b-256 |
7af954d8d2df784cd7a1b06fdecc5805ea33e06d216df01a352557c2fdf9301b
|
File details
Details for the file zap_schema-1.0.0-py3-none-any.whl.
File metadata
- Download URL: zap_schema-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3102e813fc02d12ef2dc6379bc4c79baf1f752939d146a9bae1c6b125ada62b7
|
|
| MD5 |
6093ce9da2e16dda75b8cf8977fb55a5
|
|
| BLAKE2b-256 |
bd4fdb0331ed6c785d37b6965d43eec8fc49e06f9b4033ea8e1a144ad3c5e8de
|