Skip to main content

Python SDK for ZerithDB - Headless AI agent node for P2P mesh network.

Project description

ZerithDB Python SDK (AI Agent Node)

The Python SDK for ZerithDB allows headless Python scripts to join the WebRTC mesh network just like a normal user!

Since ZerithDB syncs via a P2P mesh, you don't need a REST API to interact with the database. You can build a zerithdb-python package that runs heavy machine learning workloads (e.g., PyTorch, Transformers) on a GPU server, syncing data seamlessly.

How it works

  1. A browser user inserts a row into the database:

    app.db("jobs").insert({ text: "Translate this", status: "pending" });
    
  2. The Python script (running on a server) connects to the same WebRTC room and syncs this data via P2P.

  3. The script processes the text and updates the row:

    async def on_job_added(job):
        result = my_ml_model.process(job["text"])
        await db.table("jobs").update(job["id"], { "status": "done", "result": result })
    

Why it's cool

Developers can add heavy ML processing to their apps without building APIs, webhooks, or queues. The Python script is just another "peer" in the room!

Getting Started

pip install zerithdb-python

Basic Example

import asyncio
from zerithdb import ZerithClient

async def main():
    # Initialize the client and connect to a room
    client = ZerithClient("wss://zerith-signaling-523861363926.asia-south1.run.app")
    await client.connect("my-app-room-id")

    # Listen for new data
    @client.on("jobs:inserted")
    async def handle_job(job):
        if job["status"] == "pending":
            print(f"Processing job: {job['text']}")
            # Run your ML model here...
            await client.update("jobs", job["id"], {"status": "done", "result": "Translated text!"})

    # Keep the agent running
    await client.wait_until_disconnected()

if __name__ == "__main__":
    asyncio.run(main())

Architecture

  • Uses aiortc for WebRTC connections and data channels.
  • Uses websockets for the initial signaling phase.
  • Communicates using the standard ZerithDB CRDT sync protocol.

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

zerithdb_python-0.1.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

zerithdb_python-0.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file zerithdb_python-0.1.1.tar.gz.

File metadata

  • Download URL: zerithdb_python-0.1.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for zerithdb_python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 96e4aa8311a65b2ef50cdded0c5ebaf3153c9bd2f4996f401c2feae58e60ff56
MD5 0604b397c5a838b4a8d5d1f915f0d73a
BLAKE2b-256 8616f63466947e7e9c56d02680b100f5a89393eecbf3b98964fb55586fdba11d

See more details on using hashes here.

File details

Details for the file zerithdb_python-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for zerithdb_python-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 07a78b473547b5a7b50eb6f0f50b27bb19c87a8663a6e1bdec93af890d13a8eb
MD5 831a4ec9b4dd9c94daed07d64afe1a66
BLAKE2b-256 97407875dd3ce642ee692fbce6b069f3f51814ce5cd9086dace4330e1c6797bf

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