Metadata-Version: 2.4
Name: calimero-client-py
Version: 0.1.3
Summary: Python client SDK for Calimero Network
Home-page: https://github.com/calimero-network/calimero-client-py
Author: Calimero Network
Author-email: Calimero Network <support@calimero.network>
License: MIT
Project-URL: Homepage, https://github.com/calimero-network/calimero-client-py
Project-URL: Documentation, https://docs.calimero.network/python-sdk
Project-URL: Repository, https://github.com/calimero-network/calimero-client-py
Project-URL: Issues, https://github.com/calimero-network/calimero-client-py/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.31.0
Requires-Dist: websockets>=12.0
Requires-Dist: base58>=2.1.1
Requires-Dist: pydantic>=2.5.0
Requires-Dist: aiohttp>=3.9.0
Requires-Dist: toml>=0.10.2
Requires-Dist: pynacl>=1.5.0
Provides-Extra: test
Requires-Dist: pytest>=7.0.0; extra == "test"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "test"
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
Requires-Dist: pytest-mock>=3.10.0; extra == "test"
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# Calimero Network Python Client SDK

The **Calimero Python Client SDK** helps developers interact with decentralized apps by handling server communication. It simplifies the process, letting you focus on building your app while the SDK manages the technical details.

## Features

- JSON-RPC client for sending queries and updates to Calimero nodes
- WebSocket client for real-time subscriptions
- Authentication handling with Ed25519 keypairs
- Configuration management
- Type hints and comprehensive documentation

## Installation

```bash
pip install calimero-client-py==0.1.2
```

## Quick Start

Here's a complete example of using the SDK to interact with a key-value store:

```python
import asyncio
import toml
import os
from pathlib import Path
from calimero import JsonRpcClient, Ed25519Keypair

async def main():
    # Load keypair from config file
    config_path = os.path.expanduser("~/.calimero/node1/config.toml")
    try:
        with open(config_path, 'r') as f:
            config_data = toml.load(f)
            keypair_value = config_data.get('identity', {}).get('keypair')
            if not keypair_value:
                raise ValueError("'keypair' not found in [identity] section")
            keypair = Ed25519Keypair.from_base58(keypair_value)
    except Exception as e:
        raise ValueError(f"Failed to load keypair from config: {str(e)}")

    # Initialize the client
    client = JsonRpcClient(
        base_url="http://localhost:2428",
        endpoint="/jsonrpc",
        keypair=keypair
    )

    # Example: Set a key-value pair
    set_params = {
        "applicationId": "your_application_id",
        "method": "set",
        "argsJson": {"key": "my_key", "value": "my_value"}
    }
    set_response = await client.mutate(set_params)
    print("Set response:", set_response)

    # Example: Get a value
    get_params = {
        "applicationId": "your_application_id",
        "method": "get",
        "argsJson": {"key": "my_key"}
    }
    get_response = await client.query(get_params)
    print("Get response:", get_response)

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

### WebSocket Example

Here's how to use the WebSocket client for real-time updates:

```python
import asyncio
import toml
import os
from pathlib import Path
from calimero import WsSubscriptionsClient, Ed25519Keypair

async def main():
    # Load keypair from config file
    config_path = os.path.expanduser("~/.calimero/node1/config.toml")
    try:
        with open(config_path, 'r') as f:
            config_data = toml.load(f)
            keypair_value = config_data.get('identity', {}).get('keypair')
            if not keypair_value:
                raise ValueError("'keypair' not found in [identity] section")
            keypair = Ed25519Keypair.from_base58(keypair_value)
    except Exception as e:
        raise ValueError(f"Failed to load keypair from config: {str(e)}")

    # Initialize the client
    client = WsSubscriptionsClient(
        base_url="http://localhost:2428",
        endpoint="/ws",
        keypair=keypair
    )

    # Connect and subscribe
    await client.connect()
    client.subscribe(["your_application_id"])

    # Add callback for received messages
    def callback(data):
        print("Received update:", data)

    client.add_callback(callback)

    # Keep the connection alive
    try:
        while True:
            await asyncio.sleep(1)
    except KeyboardInterrupt:
        await client.disconnect()

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

## Documentation

For detailed documentation, please visit [our documentation site](https://docs.calimero.network).

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 

## Development

### Setting Up Development Environment

```bash
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install -e ".[test]"
```

### Running Tests

```bash
# Run all tests
pytest

# Run tests with coverage
pytest --cov=calimero

# Run specific test file
pytest tests/test_keypair.py
```

### Building and Publishing

```bash
# Install build tools
pip install --upgrade build twine

# Build the package
python -m build

# Publish to PyPI
twine upload dist/*
``` 
