# TinySDK

Shared service clients for the TinyAI microservices platform — MongoDB, MinIO, RabbitMQ, and structured logging with a consistent interface.

## Installation

```bash
pip install tinysdk
```

## Quick Start

```python
from tinysdk import TinyDBService, TinyStorageHandler, TinyMessageService, TinyMessageServiceSync, TinyLogger

# MongoDB
db = TinyDBService()
db.create({"collection": "users", "document": {"name": "John"}})

# MinIO / S3
storage = TinyStorageHandler()
storage.upload_file("my-bucket", "file.txt", buffer, size)

# RabbitMQ (async)
svc = TinyMessageService([("my-queue", handler)])
svc.publish("my-queue", {"task": "run"})
svc.run()

# RabbitMQ (sync)
svc = TinyMessageServiceSync()
svc.publish("my-queue", {"task": "run"})

# Logger
logger = TinyLogger()
logger.log("something happened", level="INFO", context={"key": "value"})
logger.start_heartbeat()  # emits periodic HEARTBEAT events

doc_logger = logger.for_document("doc-id-123")
doc_logger.log("processing started")
```

## Configuration

All clients read credentials from environment variables.

| Service | Variable | Example |
|---------|----------|---------|
| MongoDB | `DB_LINK` | `mongodb://mongo:27017` |
| MongoDB | `DB_NAME` | `tinyDatabase` |
| MinIO | `MINIO_ENDPOINT` | `minio:9000` |
| MinIO | `MINIO_ACCESSKEY` | `minioadmin` |
| MinIO | `MINIO_SECRETKEY` | `minioadmin` |
| RabbitMQ | `RABBITMQ_HOST` | `rabbitmq` |
| RabbitMQ | `RABBITMQ_PORT` | `5672` |
| RabbitMQ | `RABBITMQ_USER` | `guest` |
| RabbitMQ | `RABBITMQ_PASS` | `guest` |
| Logger | `SERVICE_NAME` | `my-service` |
| Logger | `CLUSTER` | `prod` |
| Logger | `NAMESPACE` | `default` |
| Logger | `LOG_LEVEL` | `INFO` |
| Logger | `HEARTBEAT_INTERVAL` | `30` |

Credentials can also be passed directly as constructor arguments.

## License

MIT
