Skip to main content

A core library for scalable Python applications

Project description

libcore-hng

A lightweight Python core package designed to unify access to diverse AI APIs and libraries. It provides a consistent, scalable foundation for building modular applications with clarity and flexibility.

アプリ初期処理サンプル

このプロジェクトでは、AppInitializer を用いてアプリケーションの初期化処理を行います。
初期化は一度だけ実行し、以降はグローバルインスタンス app_core を参照してください。


アプリ初期化方法

test_013_appinit.py

from libcore_hng.utils.app_core import AppInitializer
from test_013_config import DerivedConfig

class DerivedAppInitializer(AppInitializer[DerivedConfig]):
    """
    AppInitializer拡張クラス
    """
    def __init__(self, base_file: str = __file__, *config_file: str):
        # 基底コンストラクタに拡張Configクラスを渡す
        super().__init__(DerivedConfig, base_file, *config_file)

ins: DerivedAppInitializer | None = None
""" AppInitializer拡張クラスインスタンス """

def init_app(base_file: str = __file__, *config_file: str) -> DerivedAppInitializer:
    """
    アプリケーション初期化
    """
    global ins
    ins = DerivedAppInitializer(base_file, *config_file)
    return ins

test_013_config.py

from pydantic import BaseModel
from libcore_hng.core.base_config import BaseConfig
from libcore_hng.utils.app_logger_mixin import LoggingMixin

class Test(BaseModel, LoggingMixin):
    """
    テスト設定クラスモデル
    """

    append_member: str = "A"
    """ 追加メンバー """

class DerivedConfig(BaseConfig):
    """
    BaseConfig拡張クラス
    """
    
    test: Test = Test()
    """ テスト設定クラス """

    @classmethod
    def load_config(cls, base_file, *config_file) -> "DerivedConfig":
        """
        BaseConfigのload_configをoverrride
        戻り値の型は自身とする
        """

        # 基底側のload_configを実行してjsonファイルを読み込む
        base = super().load_config(base_file, *config_file)
        
        # BaseConfigのインスタンスが持つ属性を取り出してDerivedConfigのインスタンスを返す
        # **はキーワード引数に展開する構文(属性をclsに引数渡しする)
        return cls(**base.__dict__)

test_013.py

import test_013_appinit as app
import test_013_sub as t013

# アプリ初期化(最初の一度だけ呼び出す)
app.init_app(__file__, "logger.json")

# 別ファイルのメソッド
t013.test013()

test_013_sub.py

import test_013_appinit as app

def test013():
    # 拡張Configクラスのメンバーをprint
    print(app.ins.config.test.append_member)

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

libcore_hng-2.0.14.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

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

libcore_hng-2.0.14-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file libcore_hng-2.0.14.tar.gz.

File metadata

  • Download URL: libcore_hng-2.0.14.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for libcore_hng-2.0.14.tar.gz
Algorithm Hash digest
SHA256 018b1988d82fb0f59864550f7098d022a6d68cfd385e91974c188c5932b0e6a7
MD5 f178cf0aed530471cd10b2f4b5aedf43
BLAKE2b-256 fe40c54ada789e52d023d30926ebd830cda6549ef3e7505a6d37e0399dd6b66d

See more details on using hashes here.

Provenance

The following attestation bundles were made for libcore_hng-2.0.14.tar.gz:

Publisher: release.yml on kaioman/libcore-hng

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libcore_hng-2.0.14-py3-none-any.whl.

File metadata

  • Download URL: libcore_hng-2.0.14-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for libcore_hng-2.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 4a0416460f227e30b5be44eeacd8d590a2b69c0c9f89468f01e0f6120ee0a631
MD5 c5e06119e3fb3272a7c52bd2f6ee8aed
BLAKE2b-256 1e6f6743b61e71b47369fc66fdeaa3f723f153b5061ab31caa3140df9c7f36d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for libcore_hng-2.0.14-py3-none-any.whl:

Publisher: release.yml on kaioman/libcore-hng

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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