docs/integrations/prefect-dbt/api-ref/prefect_dbt-cloud-credentials.mdx
prefect_dbt.cloud.credentialsModule containing credentials for interacting with dbt Cloud
DbtCloudCredentials <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-dbt/prefect_dbt/cloud/credentials.py#L15" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>Credentials block for credential use across dbt Cloud tasks and flows.
Attributes:
api_key: API key to authenticate with the dbt Cloud
administrative API. Refer to the Authentication docs
for retrieving the API key.account_id: ID of dbt Cloud account with which to interact.domain: Domain at which the dbt Cloud API is hosted.Examples:
Load stored dbt Cloud credentials:
from prefect_dbt.cloud import DbtCloudCredentials
dbt_cloud_credentials = DbtCloudCredentials.load("BLOCK_NAME")
Use DbtCloudCredentials instance to trigger a job run:
from prefect_dbt.cloud import DbtCloudCredentials
credentials = DbtCloudCredentials(api_key="my_api_key", account_id=123456789)
async with dbt_cloud_credentials.get_administrative_client() as client:
client.trigger_job_run(job_id=1)
Load saved dbt Cloud credentials within a flow:
from prefect import flow
from prefect_dbt.cloud import DbtCloudCredentials
from prefect_dbt.cloud.jobs import trigger_dbt_cloud_job_run
@flow
def trigger_dbt_cloud_job_run_flow():
credentials = DbtCloudCredentials.load("my-dbt-credentials")
trigger_dbt_cloud_job_run(dbt_cloud_credentials=credentials, job_id=1)
trigger_dbt_cloud_job_run_flow()
Methods:
get_administrative_client <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-dbt/prefect_dbt/cloud/credentials.py#L79" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>get_administrative_client(self) -> DbtCloudAdministrativeClient
Returns a newly instantiated client for working with the dbt Cloud administrative API.
Returns:
get_client <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-dbt/prefect_dbt/cloud/credentials.py#L169" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>get_client(self, client_type: Literal['administrative', 'metadata']) -> Union[DbtCloudAdministrativeClient, DbtCloudMetadataClient]
Returns a newly instantiated client for working with the dbt Cloud API.
Args:
client_type: Type of client to return. Accepts either 'administrative'
or 'metadata'.Returns:
get_metadata_client <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-dbt/prefect_dbt/cloud/credentials.py#L93" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>get_metadata_client(self) -> DbtCloudMetadataClient
Returns a newly instantiated client for working with the dbt Cloud metadata API.
Returns: