Skip to main content

Async Snowflake connector for Python with JWT authentication

Project description

Async Snowflake Connector for Python

An async Python connector for Snowflake using JWT authentication.

Installation

pip install async-snowflake

Quick Usage

import asyncio
from async_snowflake import SnowflakeClient, SnowflakeJWTAuthClient

async def main():
    auth = SnowflakeJWTAuthClient(
        account="YOUR_ACCOUNT",
        user="YOUR_USER",
        private_key_path="/path/to/private_key.pem",
    )
    
    async with SnowflakeClient.create(
        base_url="https://your-account.snowflakecomputing.com",
        auth_client=auth,
    ) as client:
        # Execute queries
        result = await client.query.execute("SELECT * FROM users LIMIT 10")
        print(f"Rows: {result.rows}")
        print(f"Columns: {result.columns}")
        
        # List databases
        databases = await client.database.list()
        for db in databases:
            print(db.name)

asyncio.run(main())

Fluent Interface

# Account operations
await client.account.get_current_account()
await client.account.list_accounts()

# Database operations
await client.database.list()
await client.database.describe("my_db")

# Schema operations
await client.schema.list(database="my_db")
await client.schema.describe("my_db", "my_schema")

# Table operations
await client.table.list(database="my_db", schema="my_schema")

# Warehouse operations
await client.warehouse.list()
await client.warehouse.resume("warehouse_name")

# Query execution
result = await client.query.execute("SELECT * FROM table")

Using with FastAPI

from contextlib import asynccontextmanager
from fastapi import FastAPI
from async_snowflake import SnowflakeClient, SnowflakeJWTAuthClient

# Global client instance
snowflake_client: SnowflakeClient = None

@asynccontextmanager
async def lifespan(app: FastAPI):
    global snowflake_client
    
    auth = SnowflakeJWTAuthClient(
        account="YOUR_ACCOUNT",
        user="YOUR_USER",
        private_key_path="/path/to/private_key.pem",
    )
    
    snowflake_client = await SnowflakeClient.create(
        base_url="https://your-account.snowflakecomputing.com",
        auth_client=auth,
    )
    
    yield
    
    await snowflake_client.close()

app = FastAPI(lifespan=lifespan)

@app.get("/users")
async def get_users():
    result = await snowflake_client.query.execute(
        "SELECT * FROM users LIMIT 100"
    )
    return {"columns": result.columns, "rows": result.rows}

@app.get("/databases")
async def get_databases():
    databases = await snowflake_client.database.list()
    return {"databases": [db.model_dump() for db in databases]}

Configuration with Credentials File

Create a credentials.toml file:

[default]
account = "YOUR_ACCOUNT"
user = "YOUR_USER"
private_key_path = "/path/to/private_key.pem"
region = "us-east-1"

[production]
account = "PROD_ACCOUNT"
user = "admin"
private_key_path = "/path/to/prod_key.pem"

Then load with CredentialsManager:

from async_snowflake import CredentialsManager

creds = CredentialsManager(profile="default").credentials
# Use creds.account, creds.user, etc.

Or use environment variables:

export SNOWFLAKE_ACCOUNT="your_account"
export SNOWFLAKE_USER="your_user"
export SNOWFLAKE_PRIVATE_KEY_PATH="/path/to/key.pem"

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

async_snowflake-0.1.3.tar.gz (69.3 kB view details)

Uploaded Source

Built Distribution

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

async_snowflake-0.1.3-py3-none-any.whl (43.6 kB view details)

Uploaded Python 3

File details

Details for the file async_snowflake-0.1.3.tar.gz.

File metadata

  • Download URL: async_snowflake-0.1.3.tar.gz
  • Upload date:
  • Size: 69.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for async_snowflake-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4145f04709109c896e34426e169a58ad513409422c7a1811544ee6d3c22af445
MD5 ab86e9e4cdb202e32a97d86fa74689ec
BLAKE2b-256 b91dda3f5e8644930ca1b165d5b7e8da651281c5bce6b600495462d3f64fdd6d

See more details on using hashes here.

File details

Details for the file async_snowflake-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for async_snowflake-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c1a6c8a794034da7b049c1a3468a715d6d833b30b92926b89783eb1a81359691
MD5 6f125729d97b3d4cbb2c693bbf20360e
BLAKE2b-256 b45c99b23dcdf44513055d9b01cfa425b355b1f4181f2a34550bb813795f1a1d

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