How to configure codegen credentials¶
semolina codegen needs warehouse credentials to connect and introspect your
semantic views. Credentials are loaded from environment variables, a .env file,
or a TOML config file – whichever is found first.
Snowflake environment variables¶
Set these environment variables for the --backend snowflake codegen command:
Variable |
Required |
Description |
|---|---|---|
|
Yes |
Account identifier with region (e.g. |
|
Yes |
Snowflake username |
|
Yes |
Snowflake password |
|
Yes |
Compute warehouse name |
|
Yes |
Database name |
|
No |
Role to activate for the session |
|
No |
Default schema |
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
Databricks environment variables¶
Set these environment variables for the --backend databricks codegen command:
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 |
|
No |
Default schema |
export DATABRICKS_SERVER_HOSTNAME="workspace.cloud.databricks.com"
export DATABRICKS_HTTP_PATH="/sql/1.0/warehouses/abc123"
export DATABRICKS_ACCESS_TOKEN="dapi..."
semolina codegen main.analytics.orders_view --backend databricks
Use a .env file¶
Place credentials in a .env file in your working directory. The codegen CLI
picks it up automatically:
SNOWFLAKE_ACCOUNT=xy12345.us-east-1
SNOWFLAKE_USER=svc_codegen
SNOWFLAKE_PASSWORD=...
SNOWFLAKE_DATABASE=analytics
SNOWFLAKE_WAREHOUSE=compute_wh
semolina codegen my_schema.sales_view --backend snowflake
The .env file uses the same variable names as the environment variables above.
Values set in the actual environment take precedence over .env file values.
Override the .env file path with SEMOLINA_ENV_FILE¶
Set SEMOLINA_ENV_FILE to point codegen at a .env file in a different location:
export SEMOLINA_ENV_FILE="/path/to/staging.env"
semolina codegen my_schema.sales_view --backend snowflake
The priority chain for .env file resolution is:
SEMOLINA_ENV_FILEenvironment variable (highest priority)Default
.envin the current working directory
Fall back to config files¶
When environment variables and .env files are not present, codegen falls back to
TOML config files. It checks these paths in order:
.semolina.tomlin the current working directory~/.config/semolina/config.toml(user-level config)
The config file uses a [snowflake] or [databricks] section (not
[connections.X] – this fallback path is separate from the pool configuration):
[snowflake]
account = "xy12345.us-east-1"
user = "svc_codegen"
password = "..."
database = "analytics"
warehouse = "compute_wh"
[databricks]
server_hostname = "workspace.cloud.databricks.com"
http_path = "/sql/1.0/warehouses/abc123"
access_token = "dapi..."
Warning
The [snowflake] and [databricks] config file sections are a last-resort
fallback for codegen credentials only. For application connection pools, use
[connections.default] with pool_from_config() instead.
See How to connect to Snowflake or How to connect to Databricks.
Troubleshooting¶
Exit code 4 – connection failure
Codegen could not authenticate with the warehouse. Check that:
All required environment variables are set and correctly spelled
The
.envfile is in the current working directory (orSEMOLINA_ENV_FILEpoints to it)Credentials are valid (try connecting with your warehouse’s CLI tool)
Network access to the warehouse is available (VPN, firewall rules)
Credentials not found from any source
The codegen CLI raises CredentialError when
environment variables, .env file, and config files all fail to provide required
fields. The error message lists which variables are needed.
See also¶
How to generate Semolina model classes from warehouse views – full codegen CLI usage and output format
How to connect to Snowflake – Snowflake pool configuration
How to connect to Databricks – Databricks pool configuration