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.3.tar.gz (7.5 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.3-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for paradigm_garlic-0.2.3.tar.gz
Algorithm Hash digest
SHA256 71ead8110415b36f4b84e6534451acf802b6013f56096c12b48d4823545e4dea
MD5 e1f1b65fd221c68d1ea9fa2026ea5972
BLAKE2b-256 e2b68078f4fa37b23e2556c6f80670ffc4312c707e03f40ebc8b9338bd3e862d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for paradigm_garlic-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 487be2d73bbb700b359f92a358ada3e196b020249d3eb6a0b5c7a0eedbabd3d6
MD5 d11c0a04b3033636bbfb5f78c43c555a
BLAKE2b-256 9858ab7eeef1cd9c9069fc2e3a73e3597a1f751ab5825117868309d3aa552b26

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