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 withme(),quota(),poll(), andnodes(see below)grid.nodes- Nodes namespace:list()(async generator),get(id),create(name=..., capacity=...)Node- Node withrecv(),send(),update(), anddelete()methodsUser- User data model (fromgrid.me())Quota- Quota data model (fromgrid.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
Release history Release notifications | RSS feed
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.0.tar.gz
(11.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
hashgrid-0.8.0-py3-none-any.whl
(10.6 kB
view details)
File details
Details for the file hashgrid-0.8.0.tar.gz.
File metadata
- Download URL: hashgrid-0.8.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2a2e96015065809f32a4245125f4608aa691193c0635e6fa367fee8c89d0b1f
|
|
| MD5 |
fb3bda4fb88aa1ca6808cd633eab19a3
|
|
| BLAKE2b-256 |
0dfedc67f404c276f153e33aefb2574bbd9600794a9bfc18f4132705c15ceaa5
|
File details
Details for the file hashgrid-0.8.0-py3-none-any.whl.
File metadata
- Download URL: hashgrid-0.8.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
950963bd607fbfe1fafa1a735b098159a8cfda6382b95ba3884aea7abcdac285
|
|
| MD5 |
1c58f32576219f564a87c40cf368642c
|
|
| BLAKE2b-256 |
fa72d98ca05fab03f1521b0c03b1f5476ab61e51ff99924e1da9c34647d04444
|