Utilities¶
cortex_agents.utils.load_credentials ¶
Load Snowflake account URL and personal access token.
Tries provided parameters first, then falls back to environment variables. Automatically validates and normalizes the account URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
account_url
|
str | None
|
Snowflake account URL. Falls back to SNOWFLAKE_ACCOUNT_URL environment variable if not provided. |
None
|
pat
|
str | None
|
Personal access token. Falls back to SNOWFLAKE_PAT environment variable if not provided. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
Tuple of (validated_account_url, pat). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If credentials are not provided or account_url format is invalid. |
Examples:
>>> # Provide explicit credentials
>>> url, token = load_credentials(
... account_url="myaccount.snowflakecomputing.com",
... pat="my-token-123"
... )
>>> # Mix: URL from param, PAT from env
>>> url, token = load_credentials(
... account_url="myaccount.snowflakecomputing.com"
... )
Note
If python-dotenv is installed, .env files will be automatically loaded. Otherwise, only system environment variables will be used.
Source code in cortex_agents/utils.py
cortex_agents.utils.validate_account_url ¶
Validate and normalize Snowflake account URL.
Ensures the URL has https:// scheme, ends with snowflakecomputing.com, and has no trailing slashes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Account URL to validate. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Normalized account URL. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If URL format is invalid. |
Examples:
>>> validate_account_url("myaccount.snowflakecomputing.com")
"https://myaccount.snowflakecomputing.com"
>>> validate_account_url("https://myaccount.snowflakecomputing.com/")
"https://myaccount.snowflakecomputing.com"
>>> validate_account_url("https://myaccount.us-east-1.snowflakecomputing.com")
"https://myaccount.us-east-1.snowflakecomputing.com"