How to configure codegen credentials¶
semolina codegen connects to your warehouse to introspect semantic views. It
reads the same connection config as your application engines: the
[connections.<backend>] section of .semolina.toml (the same sections
create_engine() reads), with SNOWFLAKE_* / DATABRICKS_*
environment variables, and an optional .env file, filling any field the
section omits. Configure a connection once and both codegen and your engines use it.
--backend snowflake reads the [connections.snowflake] section,
--backend databricks reads [connections.databricks], and so on: the
section name matches the backend type.
Configure in .semolina.toml¶
[connections.snowflake]
type = "snowflake"
account = "xy12345.us-east-1"
user = "svc_codegen"
password = "..."
database = "analytics"
warehouse = "compute_wh"
# role = "codegen_role"
For key-pair auth, drop password and point at your private key:
[connections.snowflake]
type = "snowflake"
account = "xy12345.us-east-1"
user = "svc_codegen"
private_key_path = "/keys/rsa_key.p8"
# private_key_passphrase = "..."
database = "analytics"
warehouse = "compute_wh"
[connections.databricks]
type = "databricks"
host = "workspace.cloud.databricks.com"
http_path = "/sql/1.0/warehouses/abc123"
token = "dapi..."
catalog = "main"
[connections.duckdb]
type = "duckdb"
database = "/path/to/warehouse.db"
semolina codegen my_schema.sales_view --backend snowflake
Note
warehouse and database are required for Snowflake codegen: the
warehouse runs the introspection query and the database resolves the view
name. The query connection pool is more relaxed and treats both as optional —
see How to connect to Snowflake.
Configure with environment variables¶
Each field also reads from a prefixed environment variable, so you can skip the
TOML file entirely. Values in [connections.<backend>] take precedence over
the environment, which takes precedence over a .env file.
Variable |
Required |
Description |
|---|---|---|
|
Yes |
Account identifier with region (e.g. |
|
Yes |
Snowflake username |
|
One of |
Password (or use key-pair below) |
|
One of |
Path to a PKCS8 private key file (key-pair auth) |
|
No |
Passphrase for an encrypted private key |
|
Yes |
Compute warehouse name |
|
Yes |
Database name |
|
No |
Role to activate for the session |
export SNOWFLAKE_ACCOUNT="xy12345.us-east-1"
export SNOWFLAKE_USER="svc_codegen"
export SNOWFLAKE_PASSWORD="..."
export SNOWFLAKE_DATABASE="analytics"
export SNOWFLAKE_WAREHOUSE="compute_wh"
semolina codegen my_schema.sales_view --backend snowflake
Variable |
Required |
Description |
|---|---|---|
|
Yes |
Workspace hostname (e.g. |
|
Yes |
SQL warehouse HTTP path (e.g. |
|
Yes |
Personal access token (starts with |
|
No |
Unity Catalog name (defaults to |
export DATABRICKS_HOST="workspace.cloud.databricks.com"
export DATABRICKS_HTTP_PATH="/sql/1.0/warehouses/abc123"
export DATABRICKS_TOKEN="dapi..."
semolina codegen main.analytics.orders_view --backend databricks
Note
These match the names used by the connection pools (DATABRICKS_HOST,
DATABRICKS_TOKEN), so a single set of variables drives both codegen
and your application.
DuckDB needs no authentication. Pass the database path directly, or set
DUCKDB_DATABASE:
semolina codegen sales_view --backend duckdb --database /path/to/warehouse.db
# or
export DUCKDB_DATABASE="/path/to/warehouse.db"
semolina codegen sales_view --backend duckdb
The --database flag takes precedence over DUCKDB_DATABASE. With
neither set, DuckDB opens an empty in-memory database.
Use a .env file¶
Place the same prefixed variables in a .env file in your working directory and
codegen picks it up automatically:
SNOWFLAKE_ACCOUNT=xy12345.us-east-1
SNOWFLAKE_USER=svc_codegen
SNOWFLAKE_PASSWORD=...
SNOWFLAKE_DATABASE=analytics
SNOWFLAKE_WAREHOUSE=compute_wh
Point at a .env file elsewhere with SEMOLINA_ENV_FILE:
export SEMOLINA_ENV_FILE="/path/to/staging.env"
semolina codegen my_schema.sales_view --backend snowflake
Troubleshooting¶
Exit code 2 — connection config not found
Codegen could not assemble connection config for the backend. Check that the
[connections.<backend>] section exists (with a matching section name), or that
the required environment variables are set and spelled correctly.
Exit code 4 — connection failure
Codegen assembled config but could not authenticate or reach the warehouse. Check that credentials are valid (try your warehouse’s CLI), the key-pair path is readable, and network access is available (VPN, firewall rules).
See also¶
How to generate Semolina model classes from warehouse views – full codegen CLI usage and output format
How to connect an engine to your warehouse –
.semolina.tomlconnections andcreate_engineHow to connect to Snowflake – Snowflake pool configuration
How to connect to Databricks – Databricks pool configuration
How to connect to DuckDB – DuckDB pool configuration