Skip to main content

Production-ready foundation for Python applications

Project description

Clean-Py-Kit

Github License Coverage

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:

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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cleanpykit-0.1.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

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

Hashes for cleanpykit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 04845db9f6e48a0a0e7f21ecacb9ac07522f4e19a86f3bd0affe70aaebca19e6
MD5 cc04e11a2b1f888b863836f09e4af8d7
BLAKE2b-256 4be47ba4e4a01e357d0a86a8136a0b67de2f833d7d484e81f8c1d34267a05a25

See more details on using hashes here.

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

Hashes for cleanpykit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7b0d5654a4c65d5f33dafd4b48e8fe2d360af741351af97bd92a33231b80719
MD5 77757ca5df321bf6dae246b3189fefc6
BLAKE2b-256 5b8e4aadc561b29530d346afe457c31a68a88480bdb17c6a172c29ce7c069340

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page