garlic is a cli and python interface for Allium data
Project description
garlic 🧄
cli and python interface for interacting with Snowflake
Features
- run queries against snowflake using simple UX
- auto-convert query results to polars dataframes
- convenience functions for:
- formatting timestamps for use in SQL queries
- setting the context (warehouse, database, schema, role)
- listing catalog of databases, schemas, tables, and query history
- creating tables from select queries
Installation
uv add paradigm_garlic
Credentials
To use garlic without giving your credentials each time, add your credentials the SNOWFLAKE_CREDENTIALS environment variable
export SNOWFLAKE_CREDENTIALS='<JSON_CREDENTIALS>'
Where <JSON_CREDENTIALS> is a JSON-encoded map of credentials
For example, if using a programmatic access key:
{
"account": "abc12345.xy12345",
"user": "my_username",
"authenticator": "PROGRAMMATIC_ACCESS_KEY",
"token": "<YOUR_PROGRAMMATIC_ACCESS_TOKEN>"
}
Alternatively, can set the credentials env var in a live python session:
os.environ['SNOWFLAKE_CREDENTIALS'] = json.dumps(credentials_dict)
Or specify the credentials in each function call:
import garlic
results = garlic.query('SELECT * FROM my_table', credentials=credentials_dict)
Example Usage
Simplest example
import garlic
dataframe = garlic.query('SELECT * FROM my_table')
Set different default warehouse:
import garlic
garlic.use_warehouse('BIG_WAREHOUSE')
dataframe = garlic.query('SELECT * FROM my_table')
Read from Snowflake management tables
import garlic
databases = garlic.list_databases()
schemas = garlic.list_schemas()
tables = garlic.list_tables()
query_history = garlic.list_query_history()
Use timestamps in CLI queries
import garlic
import datetime
sql = """
SELECT *
FROM my_table
WHERE
block_timestamp >= {start_time}
AND block_timestamp < {end_time}
""".format(
start_time=garlic.format_timestamp('2024-01-01'),
end_time=garlic.format_timestamp(datetime.datetime.now()),
)
dataframe = garlic.query(sql)
Set environment context
garlic.use_warehouse('BIG_WH')
garlic.use_schema('MY_SCHEMA')
garlic.use_database('MY_DB')
garlic.use_role('MY_ROLE')
dataframe = garlic.query('SELECT * FROM my_table')
Create table from select query
import garlic
garlic.create_table(
target_table='new_table_name',
select_sql='SELECT * FROM my_table WHERE some_column = some_value',
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 paradigm_garlic-0.2.4.tar.gz.
File metadata
- Download URL: paradigm_garlic-0.2.4.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58594901e1159dfecf731a9ac015cec7f998f84449577691678c2485c85d6b56
|
|
| MD5 |
8bb110037a4820ff8a591db424baef08
|
|
| BLAKE2b-256 |
5d69af97208031a85e1da36de901f33831a2d7f642f51b05d222bf3ba59a2066
|
File details
Details for the file paradigm_garlic-0.2.4-py3-none-any.whl.
File metadata
- Download URL: paradigm_garlic-0.2.4-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13fb727e82279e9def0d77336d96289716818020a15856a65f5602cfaa3b1218
|
|
| MD5 |
5096c21565cdf7a65cb6d4aade919787
|
|
| BLAKE2b-256 |
2b3cc55e25a9fcf7ff7c96e5414219108c57edaf78f0fa4c6006b8092790540b
|