Skip to main content

prefect_dbt.cloud.clients

Module containing clients for interacting with the dbt Cloud API

Classes

DbtCloudAdministrativeClient

Client for interacting with the dbt cloud Administrative API. Args:
  • api_key: API key to authenticate with the dbt Cloud administrative API.
  • account_id: ID of dbt Cloud account with which to interact.
  • domain: Domain at which the dbt Cloud API is hosted.
Methods:

call_endpoint

Call an endpoint in the dbt Cloud API. Args:
  • path: The partial path for the request (e.g. /projects/). Will be appended onto the base URL as determined by the client configuration.
  • http_method: HTTP method to call on the endpoint.
  • params: Query parameters to include in the request.
  • json: JSON serializable body to send in the request.
Returns:
  • The response from the dbt Cloud administrative API.

create_job

Creates a new dbt Cloud job. Args:
  • project_id: Numeric ID of the project for the job.
  • environment_id: Numeric ID of the environment for the job.
  • name: Name of the job.
  • execute_steps: List of dbt commands to execute (e.g. [“dbt run”, “dbt test”]).
  • **kwargs: Additional job configuration options (e.g. triggers, settings).
Returns:
  • The response from the dbt Cloud administrative API.

delete_job

Deletes a dbt Cloud job. Args:
  • job_id: Numeric ID of the job to delete.
Returns:
  • The response from the dbt Cloud administrative API.

get_job

Return job details for a job on an account. Args:
  • job_id: Numeric ID of the job.
  • order_by: Field to order the result by. Use - to indicate reverse order.
Returns:
  • The response from the dbt Cloud administrative API.

get_job_artifact

Fetches an artifact from the most recent successful run of a job. Args:
  • job_id: The ID of the job whose latest artifact to fetch.
  • path: The relative artifact path (e.g. “manifest.json”).
Returns:
  • The response from the dbt Cloud administrative API.

get_run

Sends a request to the get run endpoint to get details about a job run. Args:
  • run_id: The ID of the run to get details for.
  • include_related: List of related fields to pull with the run. Valid values are “trigger”, “job”, “debug_logs”, and “run_steps”. If “debug_logs” is not provided in a request, then the included debug logs will be truncated to the last 1,000 lines of the debug log output file.
Returns:
  • The response from the dbt Cloud administrative API.

get_run_artifact

Sends a request to the get run artifact endpoint to fetch an artifact generated for a completed run. Args:
  • run_id: The ID of the run to list run artifacts for.
  • path: The relative path to the run artifact (e.g. manifest.json, catalog.json, run_results.json)
  • step: The index of the step in the run to query for artifacts. The first step in the run has the index 1. If the step parameter is omitted, then this method will return the artifacts compiled for the last step in the run.
Returns:
  • The response from the dbt Cloud administrative API.

list_run_artifacts

Sends a request to the list run artifacts endpoint to fetch a list of paths of artifacts generated for a completed run. Args:
  • run_id: The ID of the run to list run artifacts for.
  • step: The index of the step in the run to query for artifacts. The first step in the run has the index 1. If the step parameter is omitted, then this method will return the artifacts compiled for the last step in the run.
Returns:
  • The response from the dbt Cloud administrative API.

trigger_job_run

Sends a request to the trigger job run endpoint to initiate a job run. Args:
  • job_id: The ID of the job to trigger.
  • options: An optional TriggerJobRunOptions instance to specify overrides for the triggered job run.
Returns:
  • The response from the dbt Cloud administrative API.

DbtCloudMetadataClient

Client for interacting with the dbt cloud Administrative API. Args:
  • api_key: API key to authenticate with the dbt Cloud administrative API.
  • domain: Domain at which the dbt Cloud API is hosted.
Methods:

query

Run a GraphQL query against the dbt Cloud metadata API. Args:
  • query: The GraphQL query to run.
  • variables: The values of any variables defined in the GraphQL query.
  • operation_name: The name of the operation to run if multiple operations are defined in the provided query.
Returns:
  • The result of the GraphQL query.