# dAIEDGE Middleware Client

[![Python](https://img.shields.io/pypi/pyversions/daiedge-middleware-client)](https://pypi.org/project/daiedge-middleware-client/)
[![License](https://img.shields.io/pypi/l/daiedge-middleware-client)](https://pypi.org/project/daiedge-middleware-client/)

Python client library for the dAIEDGE Middleware API.

## About

The dAIEDGE Middleware is a core component of the [dAIEDGE Network of Excellence](https://daiedge.eu/about), designed to be a versatile bridge layer that provides communication, integration, and orchestration capabilities in complex, distributed edge AI environments.

This package provides a Python client for interacting with the dAIEDGE Middleware API, which offers functionalities for:

- **Authentication & User Management** - Secure login, logout, and user registration
- **Identity & DID Management** - Decentralized Identifiers (DID) management
- **Verifiable Credentials** - VC issuance, verification, and presentations
- **Role-Based Access Control** - Fine-grained access control policies
- **Resource Registration** - Hardware, AI models, datasets, and benchmarks
- **Marketplace** - Resource trading and listing
- **Token Management** - Token minting and balance queries
- **Licensing** - License request and validation
- **Reward System** - Manual and automatic reward distribution

## Requirements

- Python 3.10+

## Installation

```sh
pip install daiedge-middleware-client
```

## Quick Start

The default API host is already configured to `https://middleware-daiedge.bisite.usal.es/api/v1`.

```python
import asyncio
import daiedge_middleware_client
from daiedge_middleware_client import ApiClient, AuthApi
from daiedge_middleware_client.models import LoginRequest
from daiedge_middleware_client.exceptions import ApiException

async def main():
    # Use default configuration (no need to set host)
    async with ApiClient() as api_client:
        # Create an instance of the Auth API
        auth_api = AuthApi(api_client)
        
        # Login with username and password
        login_request = LoginRequest(
            username="your_username",
            password="your_password"
        )
        
        try:
            response = await auth_api.auth_login_post(login_request)
            print(f"Login successful! Session ID: {response.session_id}")
        except ApiException as e:
            print(f"Login failed: {e}")

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

## Using Session Authentication

After logging in, use the session ID for subsequent API calls by setting it in the default headers:

```python
import asyncio
import daiedge_middleware_client
from daiedge_middleware_client import ApiClient, AuthApi, IdentityApi
from daiedge_middleware_client.models import LoginRequest

async def main():
    async with ApiClient() as api_client:
        # Login first
        auth_api = AuthApi(api_client)
        login_request = LoginRequest(username="user", password="pass")
        login_response = await auth_api.auth_login_post(login_request)
        
        # Set session ID for authenticated requests
        api_client.default_headers["x-session-id"] = login_response.session_id
        
        # Now use other APIs with authentication
        identity_api = IdentityApi(api_client)
        identities = await identity_api.identities_get()
        print(f"Your identities: {identities}")

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

## Custom API Host

If you need to use a different API endpoint:

```python
import daiedge_middleware_client
from daiedge_middleware_client import Configuration

config = Configuration(
    host="https://your-custom-api.example.com/api/v1"
)
async with ApiClient(config) as api_client:
    # ...
```

## Available API Modules

| Module | Description |
|--------|-------------|
| `AccessControlApi` | Access control and permissions |
| `AuthApi` | Authentication (login, logout, signup) |
| `IdentityApi` | DID and identity management |
| `LicenseApi` | License management |
| `MarketplaceApi` | Resource marketplace |
| `PolicyApi` | Policy management |
| `RegisterAiModelApi` | AI model registration |
| `RegisterBenchmarkApi` | Benchmark registration |
| `RegisterDatasetApi` | Dataset registration |
| `RegisterHardwareApi` | Hardware registration |
| `RewardManagerApi` | Reward system |
| `RoleManagementApi` | Role management |
| `SystemPauseApi` | System pause/control |
| `TokensApi` | Token operations |
| `UsersApi` | User management |
| `VcApi` | Verifiable Credentials |
| `WalletApi` | Wallet operations |

## Documentation

- [Official Documentation](https://bisite.github.io/dAIEdge-middleware/)
- [Getting Started Guide](https://bisite.github.io/dAIEdge-middleware/docs/getting-started/)
- [Tutorials](https://bisite.github.io/dAIEdge-middleware/docs/tutorials/)
- [API Reference](https://middleware-daiedge.bisite.usal.es/api-docs)
- [About dAIEDGE](https://daiedge.eu/about)

## Development

Install development dependencies:

```sh
pip install -e ".[dev]"
# or with uv
uv sync --all-extras --dev
```

Run tests:

```sh
pytest
```

## License

Proprietary - All rights reserved.

## Author

BISITE Research group <bisite@usal.es>

## Resources

- [GitHub Repository](https://github.com/bisite/dAIEDGE-Middleware-client)
- [dAIEDGE Project Website](https://daiedge.eu)
- [dAIEDGE Middleware Docs](https://bisite.github.io/dAIEdge-middleware/)
