Skip to main content

ZAP - Zero-Copy App Proto for Python

Project description

ZAP Python

Python bindings for ZAP (Zero-Copy App Proto) - high-performance Cap'n Proto RPC for AI agents.

Inspired by FastMCP with decorator-based API.

Installation

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

Quick Start

Server

from zap import ZAP, PromptMessage

app = ZAP("my-agent", version="1.0.0")

@app.tool
def search(query: str, limit: int = 10) -> list[dict]:
    """Search for content in the knowledge base"""
    return [{"title": f"Result for {query}", "score": 0.95}]

@app.resource("file://{path}")
def read_file(path: str) -> str:
    """Read a file from disk"""
    return open(path).read()

@app.prompt
def greeting(name: str) -> list[PromptMessage]:
    """Generate a personalized greeting"""
    return [
        PromptMessage(role="system", content="You are a friendly assistant."),
        PromptMessage(role="assistant", content=f"Hello, {name}! How can I help?"),
    ]

if __name__ == "__main__":
    app.run(port=9999)

Client

import asyncio
from zap import Client

async def main():
    async with Client("localhost:9999") as client:
        # List tools
        tools = await client.list_tools()
        print(f"Available tools: {[t.name for t in tools]}")

        # Call a tool
        result = await client.call_tool("search", {"query": "hello world"})
        print(f"Search result: {result.content}")

        # Read a resource
        content = await client.read_resource("file:///tmp/test.txt")
        print(f"File content: {content.text}")

asyncio.run(main())

Features

  • FastMCP-inspired API: Decorator-based tool/resource/prompt registration
  • Zero-copy messaging: Cap'n Proto for efficient serialization
  • Full ZAP protocol: Tools, resources, prompts, logging
  • Post-quantum crypto: ML-KEM, ML-DSA, hybrid key exchange
  • W3C DID support: Decentralized identifiers (did:lux, did:key, did:web)
  • Agent consensus: Voting-based response aggregation
  • Type-safe: Full type hints with Pydantic validation

Agent Consensus

from zap import AgentConsensus, Query, Response, DID, DIDMethod

# Create consensus engine
consensus = AgentConsensus()

# Create agent DID
agent = DID(method=DIDMethod.KEY, id="z6MkAgent...")

# Submit query
query = Query.create("What is the capital of France?", agent)
consensus.submit_query(query)

# Multiple agents respond
response1 = Response.create(query.id, "Paris", agent1, confidence=0.95)
response2 = Response.create(query.id, "Paris", agent2, confidence=0.90)
consensus.submit_response(response1)
consensus.submit_response(response2)

# Agents vote
consensus.vote(query.id, response1.id, voter1)
consensus.vote(query.id, response1.id, voter2)

# Check consensus
result = consensus.try_consensus(query.id)
if result.response:
    print(f"Consensus: {result.response.content} ({result.confidence:.0%})")

Post-Quantum Cryptography

from zap import HybridKeyExchange

# Generate hybrid key pairs (X25519 + ML-KEM)
alice = HybridKeyExchange.generate()
bob = HybridKeyExchange.generate()

# Initiate exchange
x25519_pub, mlkem_pub, nonce = alice.initiate()

# Bob responds
bob_x25519, ciphertext, bob_nonce, bob_secret = bob.respond(
    x25519_pub, mlkem_pub, nonce
)

# Alice finalizes
alice_secret = alice.finalize(bob_x25519, ciphertext, nonce, bob_nonce)

assert alice_secret == bob_secret  # Shared secret established!

Related Packages

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

zap_protocol-0.2.1.tar.gz (47.0 kB view details)

Uploaded Source

Built Distribution

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

zap_protocol-0.2.1-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file zap_protocol-0.2.1.tar.gz.

File metadata

  • Download URL: zap_protocol-0.2.1.tar.gz
  • Upload date:
  • Size: 47.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for zap_protocol-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fc681fa5f354fdcd20a3f6d72e8936d232c63ed63423b5fcca3ddcc01e56dada
MD5 17aed481f931a9ba984f2c77b0bcacab
BLAKE2b-256 d9ff6f2a7af9afa4aaa3a1fe6dc0266ddfa21a2f56ba8651d4b0c39964f4c546

See more details on using hashes here.

File details

Details for the file zap_protocol-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: zap_protocol-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for zap_protocol-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c233855005d2f6108fa964e6363abadf5a6f3835303650fffa93c6da61a13d88
MD5 40701b709682cf226ef1a0b718601b82
BLAKE2b-256 93a47a926f28dbe0c091b1fb42724083708c5bdf952fe410c4ba5192f5589667

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