A command-line tool for data transformation and analytics engineering workflows.
npx @tessl/cli install tessl/pypi-dbt-core@1.10.0dbt (data build tool) is a command-line tool that enables data analysts and engineers to transform data in their warehouses by writing SQL select statements. dbt handles turning these statements into tables and views through a transformation workflow that includes dependency management, testing, documentation, and version control, bringing software engineering practices to analytics workflows.
pip install dbt-core# Main programmatic interface
from dbt.cli.main import dbtRunner, dbtRunnerResult
# Exception handling
from dbt.exceptions import (
ContractBreakingChangeError,
DbtInternalError,
DbtRuntimeError,
DbtConfigError,
DbtValidationError,
CompilationError,
CommandResultError
)
# Configuration and flags
from dbt.flags import get_flags, set_flags
from dbt.constants import DBT_PROJECT_FILE_NAME, MANIFEST_FILE_NAME
# Version information
from dbt.version import get_version_information, get_installed_versiondbt is primarily used via its command-line interface:
# Initialize a new dbt project
dbt init my_project
# Install dependencies
dbt deps
# Parse and validate project
dbt parse
# Run all models
dbt run
# Run tests
dbt test
# Generate documentation
dbt docs generate
dbt docs serveFor Python applications that need to invoke dbt programmatically:
from dbt.cli.main import dbtRunner, dbtRunnerResult
# Initialize the runner
runner = dbtRunner()
# Execute a dbt command
result: dbtRunnerResult = runner.invoke(['run', '--select', 'my_model'])
if result.success:
print("dbt run succeeded")
print(f"Result: {result.result}")
else:
print(f"dbt run failed: {result.exception}")dbt-core follows a modular architecture:
Complete CLI with commands for project lifecycle management, model execution, testing, and documentation generation.
def cli() -> None:
"""Main CLI entry point with sub-commands for all dbt operations."""Python API for embedding dbt operations in applications and workflows.
class dbtRunner:
"""Programmatic interface for invoking dbt commands."""
def __init__(
self,
manifest: Optional[Manifest] = None,
callbacks: Optional[List[Callable[[EventMsg], None]]] = None,
) -> None: ...
def invoke(self, args: List[str], **kwargs) -> dbtRunnerResult: ...
class dbtRunnerResult:
"""Result container for dbtRunner invocations."""
success: bool
exception: Optional[BaseException] = None
result: Union[
bool, # debug
CatalogArtifact, # docs generate
List[str], # list/ls
Manifest, # parse
None, # clean, deps, init, source
RunExecutionResult, # build, compile, run, seed, snapshot, test, run-operation
] = NoneSystem for managing global flags, project configuration, and runtime settings.
def get_flags():
"""Get current global flags."""
def set_flags(flags):
"""Set global flags."""
def set_from_args(args: Namespace, project_flags):
"""Set flags from command arguments."""Comprehensive exception hierarchy for structured error handling and reporting.
class ContractBreakingChangeError(DbtRuntimeError):
"""Breaking change to enforced contract."""
# Additional exceptions from dbt-common:
# DbtInternalError, DbtRuntimeError, DbtConfigError,
# DbtValidationError, CompilationError, CommandResultErrorSchema definitions and utilities for dbt artifacts like manifests, catalogs, and run results.
# Artifact schemas available in dbt.artifacts.schemas:
# - base: Base artifact schema classes
# - results: Result artifact schemas
# - catalog: Catalog artifact schemas
# - freshness: Source freshness schemas
# - manifest: Manifest artifact schemas
# - run: Run result schemasUtilities for version checking and information display.
def get_version_information() -> str:
"""Get formatted version information including core and plugins."""
def get_installed_version():
"""Get currently installed dbt-core version."""
def get_latest_version():
"""Get latest available version from PyPI."""from typing import List, Optional, Union, Callable
from argparse import Namespace
# Core types
Manifest = Any # From dbt.contracts.graph.manifest
EventMsg = Any # From dbt_common.events.base_types
CatalogArtifact = Any # From dbt.artifacts.schemas.catalog
RunExecutionResult = Any # From dbt.artifacts.schemas.run