Snowflake CLI
Snowflake CLI is an open-source command-line interface designed for developers building applications and managing workloads on Snowflake. It supports tasks across Streamlit in Snowflake, the Snowflake Native App Framework, Snowpark Container Services, and general SQL operations. The library maintains an active development pace with frequent, often monthly or bi-monthly, releases and major version updates introducing significant behavior changes.
Warnings
- breaking Snowflake CLI dropped support for Python versions below 3.10 starting with version 3.0.0. Ensure your Python environment is 3.10 or newer.
- breaking Several commands were renamed or consolidated in version 3.0.0. For instance, 'snow object stage' commands were replaced by 'snow stage' commands, and 'snow snowpark init'/'snow streamlit init' were replaced by 'snow init'.
- deprecated Snowflake CLI is the recommended modern command-line tool, replacing the legacy SnowSQL client. While SnowSQL is still available, new features and enhancements are exclusively added to Snowflake CLI.
- gotcha On MacOS and Linux systems, the `config.toml` file (default location: `~/.config/snowflake/config.toml` or `~/.snowflake/config.toml`) requires specific file permissions (read and write for the file owner only) for security. Incorrect permissions can lead to connection issues.
Install
-
pip install snowflake-cli
Quickstart
# 1. Install Snowflake CLI (if not already installed)
# pip install snowflake-cli
# 2. Add a new connection interactively
# This command will prompt you for connection details like account, user, warehouse, etc.
# For non-interactive use, consider environment variables (SNOWFLAKE_ACCOUNT, SNOWFLAKE_USER, SNOWFLAKE_PASSWORD) or a pre-configured config.toml file.
print('Run "snow connection add" and follow the prompts to set up a connection.')
print('Example prompts: \n Connection name: my_snowflake_conn\n Account: <your_account_identifier>\n User: <your_username>\n Password: <your_password>')
# Simulate environment variables for a non-interactive quickstart (replace with actual values)
import os
os.environ['SNOWFLAKE_ACCOUNT'] = os.environ.get('SNOWFLAKE_ACCOUNT', 'your_account_identifier')
os.environ['SNOWFLAKE_USER'] = os.environ.get('SNOWFLAKE_USER', 'your_username')
os.environ['SNOWFLAKE_PASSWORD'] = os.environ.get('SNOWFLAKE_PASSWORD', 'your_password')
# 3. Execute a simple SQL query using the configured connection
# Assuming a default connection 'my_snowflake_conn' has been set up
print('\nExecuting a simple SQL query:')
# Use --connection to explicitly specify the connection name
# For simplicity, if one connection is default, it might not be needed.
# In a real script, consider using `snow connection set-default my_snowflake_conn` first, or pass --connection.
import subprocess
result = subprocess.run(['snow', 'sql', '--query', 'SELECT CURRENT_VERSION()', '--connection', 'my_snowflake_conn'], capture_output=True, text=True)
print(result.stdout)
if result.stderr:
print(f"Error: {result.stderr}")
# 4. Initialize a new Streamlit in Snowflake project
# print('\nInitializing a Streamlit project:')
# subprocess.run(['snow', 'init', '--template', 'streamlit-python', 'my_streamlit_app_project'], check=True)
# print('Streamlit project "my_streamlit_app_project" created.')