Production-ready foundation for Python applications
Project description
Clean-Py-Kit
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
.yamlfiles (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:
pip install cleanpykit
Minimal Usage
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. |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cleanpykit-0.1.0.tar.gz
(8.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cleanpykit-0.1.0.tar.gz.
File metadata
- Download URL: cleanpykit-0.1.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04845db9f6e48a0a0e7f21ecacb9ac07522f4e19a86f3bd0affe70aaebca19e6
|
|
| MD5 |
cc04e11a2b1f888b863836f09e4af8d7
|
|
| BLAKE2b-256 |
4be47ba4e4a01e357d0a86a8136a0b67de2f833d7d484e81f8c1d34267a05a25
|
File details
Details for the file cleanpykit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cleanpykit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7b0d5654a4c65d5f33dafd4b48e8fe2d360af741351af97bd92a33231b80719
|
|
| MD5 |
77757ca5df321bf6dae246b3189fefc6
|
|
| BLAKE2b-256 |
5b8e4aadc561b29530d346afe457c31a68a88480bdb17c6a172c29ce7c069340
|