Metadata-Version: 2.4
Name: cleanpykit
Version: 0.1.0
Summary: Production-ready foundation for Python applications
Author: BigPocc
License: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0
Requires-Dist: pyyaml
Dynamic: license-file

# Clean-Py-Kit

[![Github](https://img.shields.io/badge/github-repo-green?logo=github)](https://github.com/BigPocc/clean-py-kit)
![License](https://img.shields.io/badge/license-MIT-blue.svg)
![Coverage](https://img.shields.io/badge/coverage-100%25-orange)


**Clean-Py-Kit** is a library made to easily structure python projects with a clean architecture.
It provides tools ready to use:

- Config loading from `.yaml` files (`cleanpykit.config`)
- Configurable logging (`cleanpykit.logging`)
- Dependecies injection container (`cleanpykit.di`)
- Application management with startup/shutdown hooks (`cleanpykit.app`)
- Useful utilities : `Result`, `singleton`, `lazy`, `cached`, `retry`, `timed` (`cleanpykit.utils`)

---

## Installation

From PyPI:

```bash
pip install cleanpykit
```

## Minimal Usage

```python
from cleanpykit.config import BaseConfig, load_config
from cleanpykit.logging import get_logger
from cleanpykit.di import Container
from cleanpykit.app import Application
from cleanpykit.utils import singleton, lazy

class Config(BaseConfig):
    log_level: str
    log_use_color: bool = True
    log_format: str = "default"

config = load_config(Config)

log = get_logger(
    __name__,
    level=config.log_level,
    fmt=config.log_format,
    use_color=config.log_use_color
)

container = Container()

@singleton
class Database:
    def __init__(self):
        self.url = "sqlite:///:memory:"

    @lazy
    def client(self):
        return object()

container.bind(Database)

app = Application(container)

def init_db():
    db = container.resolve(Database)
    log.info(f"DB initialized at {db.url}")

app.on_startup(init_db)

def cleanup():
    log.info("Cleanup done")

app.on_shutdown(cleanup)

def main():
    log.info("Application main running")
    db = container.resolve(Database)
    log.info(f"Database URL: {db.url}")

app.run(main)
```

---

## Principals Modules

| **Module** | **Featrues**                                                                                       |
|------------|----------------------------------------------------------------------------------------------------|
| `config`   | Load configuration from YAML files into typed dataclasses.                                         |
| `logging`  | Configurable logging with JSON and colored text formatters.                                        |
| `di`       | Simple dependency injection container for managing class instances.                                |
| `app`      | Application lifecycle management with startup and shutdown hooks.                                  |
| `utils`    | Utility decorators and classes like `Result`, `singleton`, `lazy`, `cached`, `retry`, and `timed`. |

---
