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
Metadata
Release files for zap-schema 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zap_schema-1.0.0.tar.gz | 57.2 kB | Without provenance | Details for zap_schema-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zap_schema-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for zap_schema-1.0.0-py3-none-any.whl |
Total release size: 76.0 kB
Release files / zap_schema-1.0.0.tar.gz
| Download URL | zap_schema-1.0.0.tar.gz |
|---|---|
| Size | 57.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
451b1ce05b6ae9c1b016e86fdbc04d62a78a0d720a970a7e61b0579954fb687d
|
|
BLAKE2b-256 checksum How to use checksums |
7af954d8d2df784cd7a1b06fdecc5805ea33e06d216df01a352557c2fdf9301b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / zap_schema-1.0.0-py3-none-any.whl
| Download URL | zap_schema-1.0.0-py3-none-any.whl |
|---|---|
| Size | 18.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3102e813fc02d12ef2dc6379bc4c79baf1f752939d146a9bae1c6b125ada62b7
|
|
BLAKE2b-256 checksum How to use checksums |
bd4fdb0331ed6c785d37b6965d43eec8fc49e06f9b4033ea8e1a144ad3c5e8de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for zap-schema 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.