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
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,seedset_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
Migration notes
From old local helpers:
app.platform.decorators.register->iisi_app_core.registerapp.platform.decorators.usecase->iisi_app_core.usecase(and other aliases)app.dependency_injection.autoload->iisi_app_core.autoloadapp.platform.decorators.feature_enabled->iisi_app_core.feature_enabled
Initialize once at app startup:
- Create/configure your
punq.Container - Call
set_default_container(container) - Call
configure_feature_flags(...)if you usefeature_enabled
Build and publish
Twine reads credentials (including API tokens) from ~/.pypirc sections [testpypi] and [pypi].
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
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 iisi_app_core-0.1.0.tar.gz.
File metadata
- Download URL: iisi_app_core-0.1.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab9ec46eeb03ca788694698e863c3b6e8e578119f46d015f7bb5ba012fa3ca57
|
|
| MD5 |
3869632b7f6a5c3cc74bc86274280901
|
|
| BLAKE2b-256 |
7f100b95126ab4f877807dff2fc33b700b7d0a605b978ce2c3011ae0892377a9
|
File details
Details for the file iisi_app_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: iisi_app_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88250ae0ca4e9cf98fecb4b17cda3a8e93c071999a17795f6b4b42dcb8513364
|
|
| MD5 |
a99ae7bacc3c12347209e7c27995958b
|
|
| BLAKE2b-256 |
f39f1c159fe1b17a7bafdca0e3ce6c224f0b9d98d87c3baaf729c3d945ecc1f1
|