If you need a connection in a support script or Jupyter notebook, you can use this snippet to get a new connection based on your dbt_project.yml and profiles.yml. Note that this is for Postgres or Redshift and doesn’t take advantage of adapters; I welcome improvements!
import psycopg2
import dbt.project
def new_conn():
project = dbt.project.read_project('dbt_project.yml')
profile = project.profiles[project['profile']]
conn_info = profile['outputs'][profile['target']]
return psycopg2.connect(host=conn_info['host'],
port=conn_info['port'],
user=conn_info['user'],
password=conn_info['pass'],
database=conn_info['dbname'])