dbt CLI

Invoke various dbt CLI commands needed for hooks to function and return their results.

Functions

add_default_args(*args[, config])

Gets the default args to give to all commands.

clean_paths(*args[, runner, config])

Clean the configured paths i.e. run the dbt clean command.

get_catalog(*args[, runner, config, ...])

Generate and return the dbt catalog for a project i.e. run the dbt docs generate command.

get_config(args)

Get the dbt config for the current runtime.

get_manifest(*args[, runner, config, ...])

Generate and return the dbt manifest for a project i.e. run the dbt parse command.

get_result(*args[, runner])

Get the result of a dbt invocation with the given args and kwargs against a given runner.

install_dependencies(*args[, runner, config])

Install additional dbt dependencies i.e. run the dbt deps command.

load_artifact(filename, config)

Load an artifact from the currently configured dbt target directory.

dbt_contracts.dbt_cli.get_config(args: Namespace) → RuntimeConfig

Get the dbt config for the current runtime. The runtime config can be used to extract common dbt args for the current runtime e.g. project_dir, profiles_dir, target_dir etc.

Parameters:

args – The parsed CLI args.

Returns:

The runtime config.

dbt_contracts.dbt_cli.add_default_args(*args: str, config: RuntimeConfig | Namespace | None = None) → list[str]

Gets the default args to give to all commands.

Parameters:

config – The runtime config to use for default args.

Returns:

The formatted CLI args.

dbt_contracts.dbt_cli.load_artifact(filename: str, config: RuntimeConfig | Namespace) → Mapping[str, Any] | None

Load an artifact from the currently configured dbt target directory.

Parameters:
  • filename – The filename of the artifact to load.

  • config – The runtime config to use when trying to load the artifact from the target path.

Returns:

The loaded artifact if found. None otherwise.

dbt_contracts.dbt_cli.get_result(*args, runner: dbtRunner = None) → dbtRunnerResult

Get the result of a dbt invocation with the given args and kwargs against a given runner.

Parameters:
  • runner – The dbtRunner to invoke commands against. If None, creates a new runner for this invocation.

  • args – Args to pass to the runner.

Returns:

The result from the invocation.

dbt_contracts.dbt_cli.clean_paths(*args, runner: dbtRunner = None, config: RuntimeConfig | Namespace = None) → None

Clean the configured paths i.e. run the dbt clean command.

Parameters:
  • runner – The dbtRunner to invoke commands against. If None, creates a new runner for this invocation.

  • config – The runtime config to use.

  • args – Args to pass to the runner.

dbt_contracts.dbt_cli.install_dependencies(*args, runner: dbtRunner = None, config: RuntimeConfig | Namespace = None) → None

Install additional dbt dependencies i.e. run the dbt deps command.

Parameters:
  • runner – The dbtRunner to invoke commands against. If None, creates a new runner for this invocation.

  • config – The runtime config to use.

  • args – Args to pass to the runner.

dbt_contracts.dbt_cli.get_manifest(*args, runner: dbtRunner = None, config: RuntimeConfig | Namespace = None, refresh: bool = False, logger: Logger = None) → Manifest

Generate and return the dbt manifest for a project i.e. run the dbt parse command.

Parameters:
  • runner – The dbtRunner to invoke commands against. If None, creates a new runner for this invocation.

  • config – The runtime config to use.

  • args – Args to pass to the runner.

  • refresh – Ignore any stored artifacts and generate a new manifest.

  • logger – The logger to use for logging.

Returns:

The manifest.

dbt_contracts.dbt_cli.get_catalog(*args, runner: dbtRunner = None, config: RuntimeConfig | Namespace = None, refresh: bool = False, logger: Logger = None) → CatalogArtifact

Generate and return the dbt catalog for a project i.e. run the dbt docs generate command.

Parameters:
  • runner – The dbtRunner to invoke commands against. If None, creates a new runner for this invocation.

  • config – The runtime config to use.

  • args – Args to pass to the runner.

  • refresh – Ignore any stored artifacts and generate a new manifest.

  • logger – The logger to use for logging.

Returns:

The catalog.