Skip to main content

Snowflake Terminal Client with Table Scrolling and Prefix Support

Project description

Winter - Snowflake Terminal Client

GitHub Python License

โ„๏ธ Winter is a powerful terminal client for Snowflake with advanced table scrolling, prefix support, security controls, and comprehensive query management.

โœจ Features

  • ๐Ÿ” Dual Authentication Support - Password authentication or RSA keypair authentication (.p8 private keys)
  • ๐Ÿ” File Browser - Interactive file browser for selecting private key files during setup
  • ๐Ÿท๏ธ Table Prefix System - Automatic prefix application to all table references (JOINs, subqueries, CTEs, DML, DDL)
  • ๐Ÿ”’ Security Controls - Default SELECT-only with configurable permissions and audit logging
  • โฐ Connection Timeout - Automatic connection timeout after 5 minutes of inactivity
  • ๐Ÿ”Œ Mandatory Connection - Must run winter connect before executing queries for better security
  • ๐Ÿ“Š Interactive Table Display - Smooth vertical and horizontal scrolling with Rich tables
  • ๐ŸŽฎ Advanced Scrolling - Arrow keys and WASD navigation without Enter key
  • ๐Ÿ“ˆ Data Analysis - Intelligent column formatting and data type detection
  • ๐Ÿ“ Export Capabilities - Export to CSV, JSON, and Excel (XLSX) formats
  • ๐Ÿ“ Query History - Automatic logging and searchable query history
  • โญ Favorites System - Save and manage favorite queries with tags
  • ๐Ÿ” Search Functionality - Search through history and favorites
  • ๐ŸŒ Multi-Environment Support - Support for different environments
  • โšก High Performance - Optimized for speed and efficiency

๐Ÿš€ Quick Start

# Install Winter
pip install winter

# Run interactive setup wizard
winter setup

# Connect to Snowflake (mandatory before queries)
winter connect

# Execute your first query (default: 10 rows, 5 columns)
winter execute-query "SELECT * FROM users"

# Use interactive table viewer
winter execute-query "SELECT * FROM users" --interactive

# Custom limits
winter execute-query "SELECT * FROM users" --limit 50 --max-columns 8

# View query history
winter history

# Manage favorite queries
winter manage-favorites

๐Ÿ“ฆ Installation

Quick Install (Recommended)

# Clone repository
git clone https://github.com/ilham-fauzi/winter.git
cd winter

# Install Winter (auto-detects OS and installs dependencies)
make install

Alternative Installation Methods

Linux/macOS

chmod +x install.sh
./install.sh

Windows

# Command Prompt
install.bat

# PowerShell
.\install.ps1

Manual Installation

# Install dependencies
pip install snowflake-connector-python cryptography pyyaml rich click inquirer openpyxl pyperclip pynput

# Install Winter
pip install .

Installation Options

  • pipx (recommended): Isolated environment
  • pip --user: User installation
  • pip: System installation
  • Development mode: For contributors

For detailed installation instructions, see INSTALL.md.

โš™๏ธ Configuration

Winter uses ~/.winter/config.yaml for configuration and supports two authentication methods:

๐Ÿ” Authentication Methods

1. Password Authentication

account: your_account.snowflakecomputing.com
user: your_username
auth_method: password
password: your_password  # Optional: leave empty to prompt each time
warehouse: COMPUTE_WH
database: YOUR_DB
schema: PUBLIC
role: YOUR_ROLE
connection_timeout: 5  # Minutes (or use hours: 0.5 = 30 minutes)

2. RSA Keypair Authentication

account: your_account.snowflakecomputing.com
user: your_username
auth_method: keypair
private_key_path: ~/.snowflake/rsa_key.p8
warehouse: COMPUTE_WH
database: YOUR_DB
schema: PUBLIC
role: YOUR_ROLE
connection_timeout: 5  # Minutes (or use hours: 0.5 = 30 minutes)

๐Ÿ”’ Security Configuration

SELECT-Only Enforcement:

  • ๐Ÿ”’ SELECT-only queries - Only SELECT statements allowed by default
  • ๐Ÿ›ก๏ธ Data protection - Prevents accidental data modification
  • ๐Ÿ” Secure by default - No DML/DDL operations allowed
  • ๐Ÿ“ Audit logging - All queries are logged for security

๐Ÿ” File Browser for Private Key Setup

Interactive File Selection:

  • ๐Ÿ” File browser - Navigate directories to find .p8 files
  • ๐Ÿ“ Smart navigation - Start from Downloads directory
  • ๐Ÿ“„ File filtering - Only shows .p8 files and directories
  • ๐Ÿ“Š File information - Shows file size and details
  • โœ… Auto-copy - Automatically copies selected file to ~/.winter/rsa_key.p8
  • ๐Ÿ” Manual search - Search for .p8 files in specific directories

Search Options:

  • ๐Ÿ“ฅ Downloads directory - Search in Downloads folder
  • ๐Ÿ–ฅ๏ธ Desktop directory - Search in Desktop folder
  • ๐Ÿ“„ Documents directory - Search in Documents folder
  • ๐Ÿ  Home directory - Search in entire home directory
  • ๐Ÿ“ Custom directory - Search in user-specified directory
  • ๐Ÿ”„ Recursive search - Finds .p8 files in subdirectories

Setup Flow:

winter setup

# Choose RSA Keypair Authentication
# Choose "Browse for .p8 file (Recommended)"
# Navigate directories OR type 'search' for manual search
# Select your .p8 file
# File automatically copied to ~/.winter/rsa_key.p8

โฐ Connection Timeout Configuration

Configurable Timeout:

  • Minutes: connection_timeout: 5 (5 minutes)
  • Hours: connection_timeout: 0.5 (30 minutes)
  • Default: 5 minutes if not specified

Password Caching:

  • ๐Ÿ” Session-based caching - Password cached until disconnect/timeout
  • ๐Ÿ”’ Secure storage - Password only stored in memory during session
  • โšก Auto-reconnect - Uses cached password for seamless reconnection
  • ๐Ÿงน Auto-clear - Password cleared on disconnect or timeout

๐Ÿ”’ Security Configuration

table_prefix: "prod_"  # Applied to all table references
security:
  allowed_all_query_types: false  # Default: SELECT-only
  audit_logging: true
  blocked_schemas: ["SENSITIVE"]
  allowed_schemas: ["PUBLIC", "ANALYTICS"]

๐Ÿ“– Usage

Connection Management

# Connect to Snowflake (mandatory before queries)
winter connect

# Test connection
winter test-connection

# Show connection info
winter connection-info

# Disconnect
winter disconnect

โš ๏ธ Important Notes:

  • You must run winter connect before executing any queries
  • Connection automatically times out after 5 minutes of inactivity
  • If connection expires, run winter connect again to reconnect

Query Execution

# Basic query execution (default: 10 rows, 5 columns)
# Note: Must run 'winter connect' first
winter execute-query "SELECT * FROM users"

# Interactive table viewer with scrolling
winter execute-query "SELECT * FROM users" --interactive

# Limit rows and columns
winter execute-query "SELECT * FROM users" --limit 50 --max-columns 8

# Query with custom prefix
winter execute-query "SELECT * FROM users" --prefix "dev_"

Table Prefix System

The prefix system automatically applies prefixes to all table references:

-- Input query
SELECT u.name, o.total 
FROM users u 
JOIN orders o ON u.id = o.user_id

-- With prefix "prod_" becomes:
SELECT u.name, o.total 
FROM prod_users u 
JOIN prod_orders o ON u.id = o.user_id

Prefix Rules:

  • โœ… Applied to: FROM, JOIN, UPDATE, INSERT INTO, DELETE FROM, TRUNCATE TABLE
  • โœ… Applied to: Subqueries, CTEs, DML, DDL statements
  • โŒ Not applied to: Schema-qualified tables (schema.table)
  • โŒ Not applied to: Database-qualified tables (db.schema.table)
  • โŒ Not applied to: Aliased tables (preserves original alias format)

Interactive Table Viewer

# Enable interactive mode
winter execute-query "SELECT * FROM large_table" --interactive

# Navigation controls:
# โ†/โ†’ : Scroll horizontally OR smart pagination
# โ†‘/โ†“ : Scroll vertically (up/down)
# WASD : Alternative navigation (W=up, A=left, S=down, D=right)
# i    : Show column information and data types
# q    : Quit interactive mode
# h    : Show help

# Smart Pagination:
# โ†’ at last columns = Next page of data
# โ† at first columns = Previous page of data

Export Functionality

# Export to single format
winter export-query "SELECT * FROM users" --format csv
winter export-query "SELECT * FROM users" --format json
winter export-query "SELECT * FROM users" --format xlsx

# Export with custom filename
winter export-query "SELECT * FROM users" --format csv --output "my_data"

# Export to multiple formats
winter export-all "SELECT * FROM users"

# Export with row limit
winter export-query "SELECT * FROM users" --limit 1000

Query History & Favorites

# View query history
winter history
winter history --limit 50

# Search query history
winter search-history "users"
winter search-history "JOIN"

# View favorite queries
winter favorites

# Add favorite query
winter add-favorite "user_summary" "SELECT id, name, email FROM users" --description "User summary query" --tags "users,summary"

# Search favorites
winter search-favorites "users"

# Delete favorite
winter delete-favorite 1

# Interactive favorite manager
winter manage-favorites

Security Management

# Check security status
winter security-status

# View audit log
winter audit-log

# Test security controls
winter security-test

# Configure security settings
winter security-config

Connection Management

# Test connection
winter test-connection

# Show connection info
winter connection-info

# Connect to Snowflake
winter connect

# Disconnect
winter disconnect

Query Analysis

# Parse and analyze query
winter parse-query "SELECT * FROM users u JOIN orders o ON u.id = o.user_id"

# Validate query
winter validate-query "SELECT * FROM users"

# Show query summary
winter query-summary "SELECT * FROM users"

๐ŸŽฎ Interactive Controls

Table Navigation

  • Arrow Keys: Navigate without Enter key
  • WASD: Alternative navigation
  • Mouse Wheel: Scroll in terminal
  • Column Info: Press i to see data types and statistics
  • Help: Press h for help

Data Display

  • Consistent Column Widths: Prevents header "heaping"
  • Intelligent Formatting: Automatic data type detection
  • Color Coding: Different colors for different data types
  • Truncation: Long values are truncated with ellipsis

๐Ÿ“Š Data Types Supported

  • ๐Ÿ“… DateTime: Cyan color, formatted display
  • ๐Ÿ“† Date: Green color, formatted display
  • ๐Ÿ”ข Integer: Magenta color, right-aligned
  • ๐Ÿ’ฐ Decimal: Yellow color, formatted numbers
  • โœ… Boolean: Blue color, true/false display
  • ๐Ÿ“ Text: White color, standard display

๐Ÿ”ง Advanced Features

Column Analysis

  • Automatic data type detection
  • Null value counting
  • Unique value analysis
  • Sample value display
  • Optimal column width suggestions

Export Formats

  • CSV: Standard comma-separated values
  • JSON: Structured JSON with metadata
  • Excel (XLSX): Full Excel format with formatting

Security Features

  • Query type validation (SELECT-only by default)
  • Schema access control
  • Audit logging
  • Session management
  • Dangerous function blocking

๐Ÿ“ File Structure

winter/
โ”œโ”€โ”€ __init__.py
โ”œโ”€โ”€ main.py                 # CLI entry point
โ”œโ”€โ”€ cli/                    # CLI components
โ”œโ”€โ”€ snowflake/              # Snowflake connection
โ”œโ”€โ”€ query/                  # Query processing and prefix system
โ”œโ”€โ”€ security/               # Security controls
โ”œโ”€โ”€ ui/                     # Interactive table viewer
โ”œโ”€โ”€ formatters/             # Data formatting and analysis
โ”œโ”€โ”€ export/                 # Export functionality
โ”œโ”€โ”€ history/                # Query history and favorites
โ”œโ”€โ”€ setup/                  # Setup wizard
โ””โ”€โ”€ utils/                  # Utility functions

๐Ÿ› ๏ธ Development

Running Locally

# From project root
python3 run_winter.py execute-query "SELECT 1"

# Or install in development mode
pip install -e .
winter execute-query "SELECT 1"

Testing

# Run all tests
python3 test_winter.py

# Run specific test modules
python3 -m pytest tests/test_query.py
python3 -m pytest tests/test_snowflake.py

Requirements

  • Python: 3.8+
  • Dependencies:
    • snowflake-connector-python>=3.0.0
    • cryptography>=3.4.8
    • pyyaml>=6.0
    • rich>=13.0.0
    • click>=8.0.0
    • inquirer>=3.0.0
    • pandas>=1.5.0
    • openpyxl>=3.0.0

๐Ÿ” Security

  • RSA Keypair Authentication: Secure .p8 key authentication
  • SELECT-only by Default: Prevents accidental data modification
  • Schema Access Control: Block or allow specific schemas
  • Audit Logging: Track all query executions
  • Session Management: Secure session handling

๐Ÿ“ Examples

Complex Query with Prefixes

-- Input
WITH user_stats AS (
  SELECT u.id, COUNT(o.id) as order_count
  FROM users u
  LEFT JOIN orders o ON u.id = o.user_id
  GROUP BY u.id
)
SELECT us.*, u.name
FROM user_stats us
JOIN users u ON us.id = u.id
WHERE us.order_count > 5

-- With prefix "prod_" becomes:
WITH user_stats AS (
  SELECT u.id, COUNT(o.id) as order_count
  FROM prod_users u
  LEFT JOIN prod_orders o ON u.id = o.user_id
  GROUP BY u.id
)
SELECT us.*, u.name
FROM user_stats us
JOIN prod_users u ON us.id = u.id
WHERE us.order_count > 5

Interactive Table Usage

# Start interactive session
winter execute-query "SELECT * FROM large_table" --interactive

# Navigate with arrow keys
# Press 'i' to see column information
# Press 'h' for help
# Press 'q' to quit

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

๐Ÿ“„ License

MIT License - see LICENSE file for details

๐Ÿ†˜ Support

๐ŸŽฏ Roadmap

  • Query result caching
  • Advanced query templates
  • Multi-database support
  • Query performance analysis
  • Custom themes and styling
  • Plugin system for extensions

Winter - Making Snowflake terminal access powerful and intuitive! โ„๏ธ

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

winter_snowflake-0.1.0.tar.gz (79.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

winter_snowflake-0.1.0-py3-none-any.whl (54.0 kB view details)

Uploaded Python 3

File details

Details for the file winter_snowflake-0.1.0.tar.gz.

File metadata

  • Download URL: winter_snowflake-0.1.0.tar.gz
  • Upload date:
  • Size: 79.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for winter_snowflake-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d12215eb4dc785e90b266c7514b4b5de279b8f372a6f8a512981b758418b6ab3
MD5 540259d6fff46ff27ee0db4b5224f17f
BLAKE2b-256 6b4f9b45a059681b65fc595140ca11df9de5b59887cff944fabb001fba04e48a

See more details on using hashes here.

File details

Details for the file winter_snowflake-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for winter_snowflake-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ec7b9de42d941b9de95da957daa04857b04d7506c331d3ac66d5717e751851d
MD5 8773459711bb0478e70d96a5f95d966d
BLAKE2b-256 8d9115b4358d28d80d524f70a11abfd31001e14e5deec1dfdd03d84bc5ec1d11

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page