Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

paradigm_garlic-0.2.6.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

paradigm_garlic-0.2.6-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file paradigm_garlic-0.2.6.tar.gz.

File metadata

  • Download URL: paradigm_garlic-0.2.6.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.0

File hashes

Hashes for paradigm_garlic-0.2.6.tar.gz
Algorithm Hash digest
SHA256 1c288723fdfffdb76edb8835ccd9b62bb4d96efe748e88f320bd7a154d570616
MD5 13afeeab8260c5b1c96bf481a37a4a13
BLAKE2b-256 9ef46545cd006a930ba8c9d72fdfa855a269785578d346f65f63d8d2bb5472dc

See more details on using hashes here.

File details

Details for the file paradigm_garlic-0.2.6-py3-none-any.whl.

File metadata

File hashes

Hashes for paradigm_garlic-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 75374f0919a6137bba777401533ddb6a22c63dafd5d778367f991500100bf0d6
MD5 dae4f59abbd45a484e9caf671ced372b
BLAKE2b-256 185be97f36a69410a7274121e82b6d4f78fe9840acef94e20deab0ac50366603

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