Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kedro Boot Apps Settings and CLIs #10

Closed
takikadiri opened this issue Jan 21, 2024 · 0 comments · Fixed by #16
Closed

Kedro Boot Apps Settings and CLIs #10

takikadiri opened this issue Jan 21, 2024 · 0 comments · Fixed by #16
Assignees

Comments

@takikadiri
Copy link
Owner

takikadiri commented Jan 21, 2024

Kedro Boot Apps are currently setted through CLI. Here is an example of setting an App using Kedro Boot CLI command kedro boot --app path.to.app_class <kedro_params>. Even if this works for regular use cases, it can be limited when we need to set the APP Class globally (at source level) and when we need to have a dedicated CLI command for a Kedro Boot App.

Settings Kedro boot Apps globally through Kedro project settings

Settings the App class through CLI can be repetitive in some cases (similar issue with kedro runner). Moreover A CLI args are a runtime/environment settings, sometimes we need to set the App class globally (at source level). We propose to use the Kedro settings.py as an additional channel to set the App Class and it's Init Args.

from kedro.config import OmegaConfigLoader  # noqa: E402

CONFIG_LOADER_CLASS = OmegaConfigLoader
CONFIG_LOADER_ARGS = {
    "config_patterns": {
        "<app_config_name>": ["<app_config_files>"..],
    }
}
from my_app_package import MyApp
APP_CLASS = MyApp
APP_ARGS = {
"init_attribute": "value"
}

The APP_ARGS are used to init the Kedro Boot App Class, they are not runtime args. Runtime/env args are setted through a config file (application.yml by default). Users could explicitely add a config file for his app by adding the associated config pattern in the CONFIG_LOADER_ARGS. Since the App object have access to the config loader through the Kedro Boot Session, it can load the appropriate configs, using the same kedro configs mechanisms.

Note that the App Class given by CLI command take precedence over App Class given by the project settings.

Extend Kedro Boot commands with Apps commands

A Kedro Boot App could have a CLI command. We need to provide a mechanism to extend the Kedro Boot CLI commands with the App Command. Here is a proposed solution path :

  • Add a subcommand level in Kedro Boot CLI commands : kedro boot <app_command_name> <app_command_params> <kedro_params>
  • Include run and dryrun as project specific commands from Kedro Boot. kedro boot --app path.to.app_class <kedro_params> would become kedro boot run --app path.to.app_class <kedro_params>
  • Create the App command through Kedro Boot Command Factory, in order to keep the CLI booting logic and kedro CLI params (pipeline, extra params, tags, ....). Here is an example of using the Kedro Boot Command Factory:
import click
from kedro_boot.framework.cli import kedro_boot_command_factory

from my_fastapi_package import MyFastapiApp


fastapi_command_params = [
    click.option(
        "--host",
        type=str,
        default="127.0.0.1",
        help="web server host",
    )
    click.option(
        "--port",
        type=str,
        default="8080",
        help="web server port",
    )
]

fastapi_command = kedro_boot_command_factory(name="fastapi", app_class=MyFastapiApp, app_params=fastapi_command_params)
[project.entry-points."kedro_boot"]
fastapi = "<my_fastapi_package.command_module:fastapi_command"

The App command could then be used as follow: kedro boot fastapi --host 127.0.0.1 --port 8000 <kedro_params>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant