LogoLogo
  • 👋Welcome to Groclake
  • ⏩Jump right in
  • 🗣️Introduction to Groclake
  • 🧠High level Concepts
    • Agent Discovery
    • Agent Registry
    • Agent Communication
      • Agent Text Transfer Protocol - ATTP
    • Agent Security
      • Agent Private Cloud - APC
      • Authentication & Encryption
      • Zero Trust Policy
  • 💽Installation & Guide
  • 🏗️Groclake Use Cases
  • 📰Groclake Records
  • Example Codes
  • GrocAgent
    • What is GrocAgent?
    • Example Chat Agent
    • Reflections in GrocAgent
      • Workflow of Reflection Handler
  • Lakes
    • 💾Data & Model Management
      • Datalake
        • Create Datalake
        • Retrieve Document
        • Upload Documents
        • Datalake Connections
          • Snowflake integration
      • Vectorlake
        • Creating vector
        • Generating Vector
        • Pushing Vector
        • Retrieve Document
        • Searching Vector
      • Modellake
        • Create Modellake
        • Language Translation
        • Conversation AI
        • Text to Speech
        • Chat Completion
      • Knowledgelake
        • Create Knowledge Base
        • Push Documents from a URL
        • Push Documents from Local Storage
        • Searching for Information
    • ⚒️Tool Management & Gateway
      • Toollake
        • Tools
        • Salesforce CRM Integration
        • Slack Communication Module
        • New Relic Integration
        • Google Calendar Integration
          • Check Slot Availability
          • Get Available Slots
          • Delete Event
          • Create new event
          • Create new calendar event
    • 🤖Agent Management & Deployment
      • Agentlake
        • Register your agent
        • Fetch agent details & categories
        • Create Agent Private Cloud (APC)
        • Assign Agent Private Cloud (APC) to an Agent
      • Promptlake
        • Setting Connection & Initializing
        • Storing a Prompt
        • Fetching a Prompt
        • Example API Calls
      • Memorylake
        • Context Component Examples
        • Value Structure
        • Setup & Guide
        • Storing & Retrieving Memory
        • Wildcard Search
        • Updating Memory Quality
    • 🗃️Index Stores
      • Cataloglake
        • Create catalog
        • Generate Product Data
        • Fetch Catalog Data
        • Push Product Data
        • Optimize Data Retrieval with Catalog Caching
        • Search for Products
        • Filter Product Search
        • Update Product Data
        • Recommend Products Based on Product Name
        • Update Inventory in Catalog
        • Fetch Inventory Details from Catalog
        • Fetch Product Price
        • Update Product Price in Catalog
        • Cache Image in Catalog
        • Sync Your Catalog with external ecomm platforms
        • Deleting items
        • Address Parsing and Intent Extraction
        • Creating Mapper
        • Convert Mapper's Metadata
        • Fetching Mapper
        • Updating Mapper
        • Example use case of Cataloglake
      • Joblake
        • Joblake Mapping
        • Creating a Joblake
      • Resumelake
        • Resumelake Mapping
        • Creating a Resumelake
Powered by GitBook
On this page
  • Requirements
  • Class: SnowflakeConnection
  1. Lakes
  2. Data & Model Management
  3. Datalake
  4. Datalake Connections

Snowflake integration

The SnowflakeConnection class enables seamless connectivity and data operations on Snowflake within the Datalake infrastructure. It is designed for AI agents and developers who need to read/write structured data securely and efficiently from Snowflake databases.


Requirements

  • A valid Snowflake account

  • A user with appropriate read/write access

  • The groclake.datalake.connection module


Class: SnowflakeConnection

Handles secure connection establishment, data querying, and writing to Snowflake.


Constructor

SnowflakeConnection(config: dict)

Parameters:

  • config (dict): Connection configuration dictionary containing:

    Key
    Description
    Example Value

    user

    Snowflake username

    "your_user"

    password

    Snowflake password

    "your_password"

    account

    Snowflake account identifier

    "xyz12345.us-east"

    warehouse

    Compute warehouse name

    "COMPUTE_WH"

    database

    Database to connect to

    "your_database"

    schema

    Schema within the database

    "your_schema"


Method: connect()

Establishes a live connection to the Snowflake instance using the provided credentials.

Example:

conn = SnowflakeConnection(config)
conn.connect()

Method: read(query: str) → list[dict]

Executes a SELECT query and returns the result as a list of dictionaries.

Example:

result = conn.read('SELECT * FROM "your_database".your_schema.employee;')
print(result)

Method: write(query: str, data: tuple)

Executes an INSERT, UPDATE, or DELETE query with parameterized values.

Example:

insert_query = """
INSERT INTO "your_database".your_schema.employee (id, name, age, department, salary)
VALUES (%s, %s, %s, %s, %s);
"""
data = (3, 'John', 52, 'Electrical', 60000)
conn.write(insert_query, data)

Method: close()

Closes the active Snowflake connection.

Example:

pythonCopyEditconn.close()

✅ Full Example

from groclake.datalake.connection import SnowflakeConnection

config = {
    "user": "your_user",
    "password": "your_password",
    "account": "your_account_id",
    "warehouse": "COMPUTE_WH",
    "database": "your_database",
    "schema": "your_schema"
}

conn = SnowflakeConnection(config)
conn.connect()

# Read from table
print(conn.read('SELECT * FROM "your_database".your_schema.employee;'))

# Insert into table
insert_query = """
INSERT INTO "your_database".your_schema.employee (id, name, age, department, salary)
VALUES (%s, %s, %s, %s, %s);
"""
data = (3, 'John', 52, 'Electrical', 60000)
conn.write(insert_query, data)

print("Data inserted successfully!")

conn.close()

🛡️ Best Practices

  • Always store credentials securely using environment variables or secrets management tools.

  • Use parameterized queries to avoid SQL injection.

  • Limit access privileges for the user specified in the config for safer operation

PreviousDatalake ConnectionsNextVectorlake

Last updated 1 month ago

💾