Skip to main content

A super simple python app framework that includes a logger and a config manager. Also usable in jupyter notebook.

Project description

loe-simp-app-fw

A super simple python app framework that includes a logger and a config manager. This framework is also useable in Jupyter Notebook.

In addition to those function, it has a CSV IO object, a Caching object to help with common data tasks.

Example

To get started,

python3 -m loe_simp_app_fw init-repo

It will generate a project structure,

project directory
├── .gitignore
├── .cache
│   └── (Hashed file name)
├── config-framework.yaml
├── config-project.yaml
├── LICENSE
├── log
│   └── 2024-04-16.log
├── README.md
└── src
    ├── configuration.py
    └── main.py

What happens after init

In configuration.py, after the initialization, it would be,

import os

from typing import ClassVar
from loe_simp_app_fw import BaseConfig, FrameworkConfig, Logger, NotInitialized, CacheManager

#---------------------------------------------------------------

# Modify the framework config location if necessary
FrameworkConfig.load(os.path.abspath("./config-framework.yaml"))


class ProjectConfig(BaseConfig):
    # Add tunable here
    example_tunable: ClassVar[str] = "ExAmPlE"

#---------------------------------------------------------------

if FrameworkConfig.developer_mode:
    # Skip loading the config
    '''
    Developer mode force the usage of the default configuration of ProjectConfig,
        i.e., the one above, rather than the one in config-project.yaml
    '''
    Logger.warning(f"Project config is now in developer mode, settings from config-project.yaml will be ignored")
else:
    # Load the config
    try:
        ProjectConfig.load(FrameworkConfig.project_config_path)
    except NotInitialized:
        Logger.warning(f"Cannot find project config file at {FrameworkConfig.project_config_path}.")
        ProjectConfig.dump_example(FrameworkConfig.project_config_path)
        Logger.info(f"Successfully create example project config at {FrameworkConfig.project_config_path}")

# Combine two config
class Config(ProjectConfig, FrameworkConfig):
    pass

# Init logger
Logger.bootstrap(Config.log_directory, log_level = Config.log_level, buffering = Config.log_buffer_size)

# Init Cache Manager
CacheManager.setup(Config.cache_directory, Config.cache_time_to_live)

Logger.info("Configuration finish initialization")

One may add additional tunables under ProjectConfig as a class variable.

In main.py, after the initialization, it would be

from loe_simp_app_fw import Logger
from configuration import Config

Basic Usage

Logger usage

from loe_simp_app_fw import Logger

Logger.debug("This is a debug message.")
Logger.info("This is a info message.")
Logger.warning("This is a warning message.")
Logger.error("This is a error message.")

Config usage

from configuration import Config

something = Config.log_level

Additional tools

from loe_simp_app_fw import isNotebook

# Return True when in a jupyter notebook environment

.gitignore

.gitignore file will be generated for the project.

In addition to the python gitignore template from GitHub, the following are also added.

# Loe's Simple App Framework
playground*
database*
config*.yaml
raw
middleware
.cache*
perf/
temp

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

loe_simp_app_fw-2.10.11.tar.gz (36.2 kB view details)

Uploaded Source

Built Distribution

loe_simp_app_fw-2.10.11-py3-none-any.whl (44.5 kB view details)

Uploaded Python 3

File details

Details for the file loe_simp_app_fw-2.10.11.tar.gz.

File metadata

  • Download URL: loe_simp_app_fw-2.10.11.tar.gz
  • Upload date:
  • Size: 36.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for loe_simp_app_fw-2.10.11.tar.gz
Algorithm Hash digest
SHA256 185fe7ece456b9d90f382d7d5a7ef7d83235106667efba8578a259b0b5533c5b
MD5 8195e6b5216181ff338673494c3eab0f
BLAKE2b-256 d5f25fdeadaebd47935a08a1ff538d7e493ad47e7256f17d530889c4dfe4198c

See more details on using hashes here.

File details

Details for the file loe_simp_app_fw-2.10.11-py3-none-any.whl.

File metadata

File hashes

Hashes for loe_simp_app_fw-2.10.11-py3-none-any.whl
Algorithm Hash digest
SHA256 02b4214b51e99dbdbd483ee864bd960b9130ff1119deeac639700ad0fe2ce432
MD5 888389acf5238151ecf74844c9270d9d
BLAKE2b-256 dc0643ba54e22e265c717778995d4160b272af72bcc84f391ec49751a04bd4bc

See more details on using hashes here.

Supported by

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