cliconf package

Framework that lets you write CLIs with Typer that can also be configured via py-app-conf

Submodules

cliconf.arg_store module

class cliconf.arg_store.ArgumentStore(**data)[source]

Bases: BaseModel

This class is used to store the arguments that are passed to the CLI.

add_command(prog_name, args, params)[source]
args_are_stored_for(prog_name)[source]
Return type:

bool

commands: Dict[str, CommandArgs]
remove_command(prog_name)[source]
class cliconf.arg_store.CommandArgs(**data)[source]

Bases: BaseModel

params: Dict[str, Any]
passed_args: List[Any]
prog_name: str

cliconf.command module

class cliconf.command.CLIConfCallable[source]

Bases: object

cliconf_settings: CLIConfSettings
model_cls: Type[BaseConfig]
pyappconf_settings: AppConfig
cliconf.command.get_command(typer_instance)[source]

Extends typer’s get_command function to modify the created click.Command instance to inspect the passed arguments and load from config.

Return type:

Command

cliconf.command_name module

cliconf.command_name.get_command_name(name)[source]
Return type:

str

cliconf.configure module

cliconf.configure.configure(pyappconf_settings, cliconf_settings=CLIConfSettings(generate_config_option_name='config-gen', base_cls=None, make_fields_optional=True, recursive_loading=False, inject_model=False))[source]
Return type:

Callable

cliconf.configure.model_as_dict(model)[source]

Only serialize the top-layer of the model to a dict, leave nested models as Pydantic models

Return type:

Dict[str, Any]

cliconf.dynamic_config module

cliconf.dynamic_config.create_dynamic_config_class_from_function(func, settings, base_cls=None, model_is_injected=False, make_optional=True)[source]

Create a BaseConfig class from a function.

cliconf.dynamic_config.filter_func_args_and_kwargs_to_get_user_passed_data(func, func_args, func_kwargs)[source]
Return type:

Dict[str, Any]

cliconf.dynamic_config_name module

cliconf.dynamic_config_name.dynamic_model_class_name(func)[source]
Return type:

str

cliconf.ext_inspect module

cliconf.ext_inspect.get_function_args(func)[source]
Return type:

List[str]

cliconf.ext_inspect.get_function_params(func, model_is_injected=False, make_optional=True)[source]

cliconf.ext_pyappconf module

class cliconf.ext_pyappconf.CLIAppConfig(**kwargs)[source]

Bases: AppConfig

Overrides some of the default settings for pyappconf to be more reasonable for what users would typically want to use in a CLI application.

  • Updates default folder to be the current directory

  • Outputs stub file for Python config format

__init__(**kwargs)[source]
cliconf.ext_pyappconf.create_cli_base_config_class(base_cls, settings=None)[source]
Return type:

Type[BaseConfig]

cliconf.ext_pyappconf.save_model(model, func)[source]
Return type:

None

cliconf.ext_typer module

cliconf.ext_typer.get_arg_names_that_can_be_processed_by_typer(callback)[source]
Return type:

List[str]

cliconf.ext_typer.is_typer_parameter_info(argument)[source]
Return type:

TypeGuard[ParameterInfo]

cliconf.logger module

class cliconf.logger.LogLevel(value)[source]

Bases: str, Enum

An enumeration.

DEBUG = 'DEBUG'
INFO = 'INFO'
class cliconf.logger.LoggingConfig(_env_file='<object object>', _env_file_encoding=None, _env_nested_delimiter=None, _secrets_dir=None, **values)[source]

Bases: BaseSettings

class Config[source]

Bases: object

env_prefix = 'CLICONF_LOG_'
classmethod cast_log_level(v)[source]
level: LogLevel

cliconf.main module

class cliconf.main.CLIConf(*args, **kwargs)[source]

Bases: Typer

cliconf.options module

cliconf.options.create_generate_config_option(supported_formats, default_format, model_cls, func, option_name='config-gen')[source]
Return type:

Option

cliconf.py_api module

cliconf.py_api.execute_cliconf_func_as_python_func(func, model_is_injected, *args, **kwargs)[source]

Execute a cliconf function as a normal python function.

Unwraps any typer options and arguments that may be used as defaults.

Return type:

Any

cliconf.settings module

class cliconf.settings.CLIConfSettings(**data)[source]

Bases: BaseModel

Settings for the CLI configuration that are specific to cliconf

base_cls: Optional[Type[BaseConfig]]
generate_config_option_name: str
inject_model: bool
make_fields_optional: bool
recursive_loading: bool

cliconf.testing module

class cliconf.testing.CLIRunner(charset='utf-8', env=None, echo_stdin=False, mix_stderr=True)[source]

Bases: CliRunner

invoke(app, args=None, input=None, env=None, catch_exceptions=True, color=False, **extra)[source]

Invokes a command in an isolated environment. The arguments are forwarded directly to the command line script, the extra keyword arguments are passed to the main() function of the command.

This returns a Result object.

Parameters:
  • cli – the command to invoke

  • args (Union[str, Sequence[str], None]) – the arguments to invoke. It may be given as an iterable or a string. When given as string it will be interpreted as a Unix shell command. More details at shlex.split().

  • input (Union[bytes, str, IO[Any], None]) – the input data for sys.stdin.

  • env (Optional[Mapping[str, str]]) – the environment overrides.

  • catch_exceptions (bool) – Whether to catch any other exceptions than SystemExit.

  • extra (Any) – the keyword arguments to pass to main().

  • color (bool) – whether the output should contain color codes. The application can still override this explicitly.

Changed in version 8.0: The result object has the return_value attribute with the value returned from the invoked command.

Changed in version 4.0: Added the color parameter.

Changed in version 3.0: Added the catch_exceptions parameter.

Changed in version 3.0: The result object has the exc_info attribute with the traceback if available.

Return type:

Result