Skip to main content

Dependency-injection decorators, autoload utilities, and feature flags for punq-based apps.

Project description

iisi-app-core

iisi-app-core is a small Python library for punq-based applications that provides:

  • DI registration decorators (register + aliases)
  • Recursive package autoloading (autoload)
  • Feature-flag decorator (feature_enabled) with configurable integration points
  • AWS-oriented platform handlers:
    • ApiGatewayEventHandler
    • EventBridgeEventHandler
    • JwtTokenHandler
    • CorsPreflightRestHandler

Requirements

  • Python >=3.14,<4
  • punq (installed automatically with this package)

Installation

pip install iisi-app-core

Quickstart

from punq import Container

from iisi_app_core import autoload, set_default_container, usecase

container = Container()
set_default_container(container)


class IUserRepo:
    ...


@repository
class UserRepo(IUserRepo):
    ...

# Import every module under app.contexts to trigger decorator registration
import app.contexts

autoload(app.contexts)

Feature flags

feature_enabled needs a settings interface that can be resolved from the active punq.Container.

from iisi_app_core import (
    FeatureDisabledError,
    configure_feature_flags,
    feature_enabled,
)


class SettingsStore:
    def is_feature_enabled(self, name, default=False) -> bool:
        ...


configure_feature_flags(settings_interface=SettingsStore)

@usecase
@feature_enabled("/feature/auth/register_user", message="Registration disabled")
class RegisterUser:
    def __call__(self, command):
        return "ok"

App-specific compatibility configuration

If your app uses dedicated value objects and exceptions, configure them once:

from app.platform.domain.errors import FeatureDisabled
from app.platform.domain.ports import SettingsStore
from app.platform.domain.value_objects import SettingName
from iisi_app_core import configure_feature_flags

configure_feature_flags(
    settings_interface=SettingsStore,
    setting_name_factory=SettingName,
    disabled_exception=FeatureDisabled,
)

API overview

  • register(cls=None, *, interface=None, container=None)
  • component, adapter, controller, policy, repository, service, usecase, seed
  • set_default_container(container), get_default_container(), clear_default_container()
  • autoload(package)
  • feature_enabled(feature_path, default=True, message=None, *, settings_interface=None, setting_name_factory=None, disabled_exception=None, container=None)
  • configure_feature_flags(settings_interface, *, setting_name_factory=None, disabled_exception=None)
  • clear_feature_flag_config()
  • FeatureDisabledError
  • ApiGatewayEventHandler, EventBridgeEventHandler
  • JwtTokenHandler
  • CorsPreflightRestHandler, CorsResponseHandler

Migration notes

From old local helpers:

  • app.platform.decorators.register -> iisi_app_core.register
  • app.platform.decorators.usecase -> iisi_app_core.usecase (and other aliases)
  • app.dependency_injection.autoload -> iisi_app_core.autoload
  • app.platform.decorators.feature_enabled -> iisi_app_core.feature_enabled
  • app.platform.handlers.event.ApiGatewayEventHandler -> iisi_app_core.ApiGatewayEventHandler
  • app.platform.handlers.event.EventBridgeEventHandler -> iisi_app_core.EventBridgeEventHandler
  • app.platform.handlers.jwt.JwtTokenHandler -> iisi_app_core.JwtTokenHandler
  • app.platform.handlers.cors.CorsPreflightRestHandler -> iisi_app_core.CorsPreflightRestHandler

Initialize once at app startup:

  1. Create/configure your punq.Container
  2. Call set_default_container(container)
  3. Call configure_feature_flags(...) if you use feature_enabled

Build and publish

Twine reads credentials (including API tokens) from ~/.pypirc sections [testpypi] and [pypi].

Prepare environment:

python3.14 -m venv .venv
source .venv/bin/activate
pip install pip-tools
pip install -e '.[dev]'

Build:

python -m build

Upload to TestPyPI:

python -m twine upload -r testpypi dist/*

Upload to PyPI:

python -m twine upload -r pypi dist/*

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

iisi_app_core-0.1.1.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

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

iisi_app_core-0.1.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file iisi_app_core-0.1.1.tar.gz.

File metadata

  • Download URL: iisi_app_core-0.1.1.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for iisi_app_core-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b3758d21789cf241f4650133a26c7a01cb8083586f4ef42eaace74ebbe4decbd
MD5 36d186ac7a19da7161a8d246bf9022c7
BLAKE2b-256 fe99289bf1e8228c3f47abfacb81991da418b06430bd8590f778ecf1c01ecce1

See more details on using hashes here.

File details

Details for the file iisi_app_core-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: iisi_app_core-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for iisi_app_core-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a72a68e3e73321b3070550702d92240402af25ffd5e5fa4c91a1aa6cc712ec42
MD5 ef3d88ddf54ef0e7124b267da40f0962
BLAKE2b-256 71e4b636dc438c6c279be85669cb84c6e2eb0005730e04f54594ac38e74a90da

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