Skip to content

# `cli`

Here's the reference for the CLI configuration helpers used to load settings from `pyproject.toml`.

You can import them directly from `fastapi_toolsets.cli.config`:

    from fastapi_toolsets.cli.config import (
        import_from_string,
        get_config_value,
        get_fixtures_registry,
        get_db_context,
        get_custom_cli,
    )

## `fastapi_toolsets.cli.config.import_from_string(import_path)`

Import an object from a dotted string path.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`import_path` | `str` | Import path in `"module.submodule:attribute"` format | required

Returns:

Type | Description
--- | ---
`Any` | The imported attribute

Raises:

Type | Description
--- | ---
`BadParameter` | If the import path is invalid or import fails

## `fastapi_toolsets.cli.config.get_config_value(key, required=False)`

    get_config_value(key: str, required: Literal[True]) -> Any

    get_config_value(
        key: str, required: bool = False
    ) -> Any | None

Get a configuration value from pyproject.toml.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`key` | `str` | The configuration key in [tool.fastapi-toolsets]. | required
`required` | `bool` | If True, raises an error when the key is missing. | `False`

Returns:

Type | Description
--- | ---
`Any | None` | The configuration value, or None if not found and not required.

Raises:

Type | Description
--- | ---
`BadParameter` | If required=True and the key is missing.

## `fastapi_toolsets.cli.config.get_fixtures_registry()`

Import and return the fixtures registry from config.

## `fastapi_toolsets.cli.config.get_db_context()`

Import and return the db_context function from config.

## `fastapi_toolsets.cli.config.get_custom_cli()`

Import and return the custom CLI Typer instance from config.

## `fastapi_toolsets.cli.utils.async_command(func)`

Decorator to run an async function as a sync CLI command.

Example

    @fixture_cli.command("load")
    @async_command
    async def load(ctx: typer.Context) -> None:
        async with get_db_context() as session:
            await load_fixtures(session, registry)