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.2.tar.gz (68.1 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.2-py3-none-any.whl (43.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: async_snowflake-0.1.2.tar.gz
  • Upload date:
  • Size: 68.1 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.2.tar.gz
Algorithm Hash digest
SHA256 11ed48437ec66b33852f9b815eda00103d6c7ff292d275c95bde86d019ae412c
MD5 a8e9a38a07ad291539111eeab053de4f
BLAKE2b-256 1520d0281fe0d132927f3280d163bf90c945b397503676c6944fc361dfee1a2f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for async_snowflake-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 af225670bcdca78760448c1276397bb3955973ffc284846c30661bd0d4673846
MD5 57fc4846a182b7fc3beec23b3686b7aa
BLAKE2b-256 6cb172cf89d2a91b3908cee492c1ef65db3338a7523176d9a13ceb652166ec72

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