Metadata-Version: 2.4
Name: hashgrid
Version: 0.8.1
Summary: Hashgrid Client - Python SDK
Author: Hashgrid
License: MIT
Project-URL: Homepage, https://hashgrid.ai
Project-URL: Documentation, https://dna.hashgrid.ai/docs
Keywords: hashgrid,client,sdk
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: httpx

# Hashgrid Client

Python SDK for the Hashgrid Protocol API.

## Installation

```bash
pip install hashgrid
```

## Quick Start

```python
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

```python
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
