Command Line Interface¶
Important
The Airflow Core version must be 3.2.0 or newer to be able to use provider-level CLI commands.
If your provider include Auth managers or Executors, you should also implement the provider-level CLI commands to improve the Airflow CLI response speed and avoid loading heavy dependencies when those commands are not needed.
Even if your auth manager or executor do not implement the get_cli_commands interface (airflow.api_fastapi.auth.managers.base_auth_manager.BaseAuthManager.get_cli_commands() or airflow.executors.base_executor.BaseExecutor.get_cli_commands()), you should still implement provider-level CLI commands that return empty list to avoid loading auth manager or executor code for every CLI command, which will also resolve the following warning:
Please define the 'cli' section in the provider.yaml for custom auth managers to avoid this warning.
For community providers, please update to the version that support '.cli.definition.get_cli_commands' function.
For more details, see https://airflow.apache.org/docs/apache-airflow-providers/core-extensions/cli-commands.html
Please define the 'cli' section in the provider.yaml for custom executors to avoid this warning.
For community providers, please update to the version that support '.cli.definition.get_cli_commands' function.
For more details, see https://airflow.apache.org/docs/apache-airflow-providers/core-extensions/cli-commands.html
Implementing provider-level CLI Commands¶
To implement provider-level CLI commands, follow these steps:
Define all your CLI commands in
airflow.providers.<your_provider_name>.cli.definitionmodule. Additionally, you should avoid defining heavy dependencies in this module to reduce the Airflow CLI startup time. Please useairflow.cli.cli_config.lazy_load_commandutility to lazily load the actual callable to run.
from airflow.cli.cli_config import (
ActionCommand,
Arg,
GroupCommand,
lazy_load_command,
)
@staticmethod
def get_my_cli_commands() -> list[GroupCommand]:
executor_sub_commands = [
ActionCommand(
name="executor_subcommand_name",
help="Description of what this specific command does",
func=lazy_load_command("path.to.python.function.for.command"),
args=Arg(
"--my-arg",
help="Description of my arg",
action="store_true",
),
),
]
auth_manager_sub_commands = [
ActionCommand(
name="auth_manager_subcommand_name",
help="Description of what this specific command does",
func=lazy_load_command("path.to.python.function.for.command"),
args=(),
),
]
custom_sub_commands = [
ActionCommand(
name="custom_subcommand_name",
help="Description of what this specific command does",
func=lazy_load_command("path.to.python.function.for.command"),
args=(),
),
]
return [
GroupCommand(
name="my_cool_executor",
help="Description of what this group of commands do",
subcommands=executor_sub_commands,
),
GroupCommand(
name="my_cool_auth_manager",
help="Description of what this group of commands do",
subcommands=auth_manager_sub_commands,
),
GroupCommand(
name="my_cool_custom_commands",
help="Description of what this group of commands do",
subcommands=custom_sub_commands,
),
]
Update
clisection of your provider’sprovider.yamlfile to point to the function that returns the list of CLI commands. For example:
cli:
- airflow.providers.<your_provider_name>.cli.definition.get_my_cli_commands
Update
get_provider_info.pyfile of your provider to include the CLI commands in the returned dictionary. For example:
def get_provider_info() -> dict[str, list[str]]:
return {
# ...
"cli": ["airflow.providers.<your_provider_name>.cli.definition.get_my_cli_commands"],
# ...
}
You can read more about provider.yaml and get_provider_info.py in How to create your own provider.
Community-Managed Provider CLI Commands¶
This is a summary of all Apache Airflow Community provided implementations of CLI commands exposed via community-managed providers.
Note
For example, if you are using KubernetesExecutor and you encounter the Please define the 'cli' section in the provider.yaml for custom executors to avoid this warning. warning during CLI usage, ensure that you have updated to a version of the provider that includes the necessary CLI command definitions as described below.
Those provided by the community-managed providers: