dbt-adapters
dbt-adapters is a Python library that defines the set of adapter protocols and base functionality crucial for integrating dbt-core with various data platforms. It serves as the foundational interface for developing database-specific dbt adapters. As of its current version 1.22.9, it's an actively developed component within the dbt ecosystem, with a release cadence that is increasingly independent of dbt-core, especially since dbt-core v1.8.
Warnings
- breaking Breaking changes in dbt-core v1.8+ for adapter developers. dbt-core and dbt-adapters were decoupled. Adapters should no longer directly import from `dbt-core` and instead rely on interfaces defined in `dbt-adapters` and `dbt-common`. Users must explicitly install `dbt-core` and their specific `dbt-<adapter>` package.
- gotcha Adapter methods like `get_response` and `execute` are expected to return `connection.AdapterResponse` objects, not just strings, since `dbt-core` v1.1. Custom adapters that return strings might face unexpected behavior.
- gotcha Correct configuration of `profiles.yml` is essential. Missing or incorrect entries, or failing to install the corresponding `dbt-<database-adapter>` package, will prevent dbt from connecting to your data warehouse and result in errors like 'Error importing adapter: No module named...'
- deprecated Starting with `dbt-core` v1.10, deprecation warnings are raised for custom inputs, duplicate YAML keys, and unexpected Jinja blocks. While initially warnings, these will become errors in future versions.
- breaking Changes to dbt artifact schema versions (e.g., manifest.json) require compatible `dbt-core` versions when using state-based functionality (`--state` flag). Mismatched schema versions will cause errors and require concurrent upgrades of dbt orchestrations.
Install
-
pip install dbt-adapters -
pip install dbt-core dbt-<your-database-adapter>
Imports
- BaseAdapter
from dbt.adapters.base.impl import BaseAdapter
- SQLAdapter
from dbt.adapters.sql.impl import SQLAdapter
- adapter (Jinja context variable)
{% do adapter.dispatch('macro_name', 'package_name')(arg1, arg2) %}
Quickstart
# 1. Install dbt-core and your specific database adapter (e.g., dbt-postgres)
# pip install dbt-core dbt-postgres
# 2. Initialize a dbt project
# dbt init my_dbt_project
# cd my_dbt_project
# 3. Configure your profiles.yml (typically in ~/.dbt/profiles.yml)
# Example profiles.yml content (replace with your database details):
# my_dbt_project:
# target: dev
# outputs:
# dev:
# type: postgres
# host: localhost
# user: myuser
# password: "{{ env_var('DB_PASSWORD') }}"
# port: 5432
# dbname: mydatabase
# schema: public
# 4. Create a dbt model (e.g., models/my_model.sql)
# Use the 'adapter' object in Jinja to call adapter-specific functionality.
# For instance, to get the current timestamp, which might vary by database dialect:
-- my_model.sql
SELECT
{{ adapter.dispatch('current_timestamp', 'dbt')() }} as current_time,
1 as id