https://dagster.io/ logo
#ask-ai
Title
# ask-ai
d

Darryl Ng

02/20/2024, 1:38 AM
@Scout How can I run
dbt ls
and get the results back using dbt cli ?
s

Scout

02/20/2024, 1:38 AM
To run the
dbt ls
command and retrieve the results using the dbt CLI through Dagster, you would typically use the
DbtCliResource
provided by the
dagster_dbt
library. The
DbtCliResource
allows you to execute dbt CLI commands and interact with the output. Here's a general example of how you might use the
DbtCliResource
to run the
dbt ls
command, based on the documentation:
Copy code
python from dagster_dbt import DbtCliResource  # Instantiate the DbtCliResource with the appropriate project directory dbt = DbtCliResource(project_dir="/path/to/dbt/project")  # Run the `dbt ls` command dbt_cli_invocation = dbt.cli(["ls"]).wait()  # Retrieve the raw output (stdout) of the dbt CLI process raw_output = dbt_cli_invocation.raw_output  # The raw_output variable now contains the results of the `dbt ls` command print(raw_output)
In this example, you create an instance of
DbtCliResource
with the necessary configuration, such as the
project_dir
. Then, you invoke the
cli
method with the arguments for the dbt command you want to run, in this case,
["ls"]
. After waiting for the command to complete with
.wait()
, you can access the raw output of the command using the
raw_output
attribute of the invocation object. Please note that the exact implementation details may vary depending on your specific setup and the version of the
dagster_dbt
library you are using. Always refer to the latest documentation for the most accurate and up-to-date usage instructions.
5 Views