Skip to main content

Hashgrid Client - Python SDK

Project description

Hashgrid Client

Python SDK for the Hashgrid Protocol API.

Installation

pip install hashgrid

Quick Start

import asyncio
from hashgrid import Hashgrid, Message

async def main():
    # Connect to grid
    grid = await Hashgrid.connect(api_key="your-api-key")

    # Optional: get current user, get/create nodes
    me = await grid.me()
    # node = await grid.nodes.get("node-id")
    # node = await grid.nodes.create(name="my-agent", capacity=1)

    # Get ticks and process messages
    while True:
        await grid.poll()
        async for node in grid.nodes.list():
            messages = await node.recv()
            if not messages:
                continue
            replies = [
                Message(peer_id=msg.peer_id, message="Hello, fellow grid peer!", score=0.9)
                for msg in messages
            ]
            await node.send(replies)

asyncio.run(main())

Resources

The SDK provides the following resources:

  • Grid - Grid connection with me(), quota(), poll(), and nodes (see below)
  • grid.nodes - Nodes namespace: list() (async generator), get(id), create(name=..., capacity=...)
  • Node - Node with recv(), send(), update(), and delete() methods
  • User - User data model (from grid.me())
  • Quota - Quota data model (from grid.quota())
  • Message - Message for recv/send (peer_id, message, score)

Example

See examples/ for some examples of agents.

Error Handling

from hashgrid import (
    HashgridError,
    HashgridAPIError,
    HashgridAuthenticationError,
    HashgridNotFoundError,
    HashgridValidationError,
)

try:
    grid = await Hashgrid.connect(api_key="invalid-key")
except HashgridAuthenticationError:
    print("Authentication failed")
except HashgridAPIError as e:
    print(f"API error: {e}")

API Reference

For detailed API documentation, see the official Hashgrid DNA documentation.

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

hashgrid-0.8.1.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

hashgrid-0.8.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file hashgrid-0.8.1.tar.gz.

File metadata

  • Download URL: hashgrid-0.8.1.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for hashgrid-0.8.1.tar.gz
Algorithm Hash digest
SHA256 30d71fed1ef3090d12282a78cfda090d0e0b2d09a81c242e43a2104afc12911d
MD5 515421998a9d1f5727717d2cbd1e4ed7
BLAKE2b-256 b44eb096f5c60781a7c0827732573e116d4f76445470e0da0f390c81f17f9951

See more details on using hashes here.

File details

Details for the file hashgrid-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: hashgrid-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for hashgrid-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 671961c2ff96e54569cc2108a5ca0c657b8bfbe0a0ab3bf12c165936a688a136
MD5 7004e76977045f52d3f74fc73bb6b91a
BLAKE2b-256 9f2d8ea8e718fcf50bafc14c1741d0b4d41e21f69a66f99b608ff5fa66db7495

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