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

Basic Example

import asyncio
from zerithdb import ZerithClient

async def main():
    # Initialize the client and connect to a room
    client = ZerithClient("wss://signal.zerithdb.dev")
    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.0.tar.gz (5.0 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.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zerithdb_python-0.1.0.tar.gz
  • Upload date:
  • Size: 5.0 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.0.tar.gz
Algorithm Hash digest
SHA256 3b92f04d6094070a3df713f7690ee5c14d1d7fe7c374b00ad703b67ec035d8e8
MD5 e84a43e07ff7baa070c0a8614ff201b8
BLAKE2b-256 c7285077dd638ef2da0fde645061b03143ee6e069c2eb697e4af0c6fabd111e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zerithdb_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b53a40b3dfed7e687d2c57425c9c7288b5276349fcb3092b988edea974f7562c
MD5 bdd23af3d79b02d78d7bab6f5024f698
BLAKE2b-256 b91ee59f7905ea948922992887d0238a7613aa110bbd7e4429314447029cb30b

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