Snowflake CLI

3.16.0 · active · verified Mon Apr 13

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

Install

Quickstart

This quickstart demonstrates how to install Snowflake CLI, configure a new connection, and execute a basic SQL query. It also shows how to initialize a project from a template. For authentication, it relies on environment variables or an interactively configured `config.toml` file.

# 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.')

view raw JSON →