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.1.tar.gz
(68.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file async_snowflake-0.1.1.tar.gz.
File metadata
- Download URL: async_snowflake-0.1.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45bbfb47b35dbc80d5faa1ce3c339eb63376359acbffdc318d3068d9582353c3
|
|
| MD5 |
9fb8102d69dac81e28f0113661cf4e16
|
|
| BLAKE2b-256 |
bd8e07b7d7119f27827b1788428d90290bb1e2755e85f2a838caa791bafe6f50
|
File details
Details for the file async_snowflake-0.1.1-py3-none-any.whl.
File metadata
- Download URL: async_snowflake-0.1.1-py3-none-any.whl
- Upload date:
- Size: 43.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a891e941ad94cb913b957dd2626039fafa5fcdf15ef62ed67ea2016b31983ce8
|
|
| MD5 |
441a297a7292f6a5bdd7887f19e1b4ca
|
|
| BLAKE2b-256 |
73a7bdcb80c322668a2096fd0224b193f903e30c0354db8ea729ab344cc88691
|