Skip to main content

Python package to manipulate Snowsight worksheets

Project description

sfgit logo

image image License: MIT Coverage Badge

Snowflake Git

🆕 Git now supported in Snowflake, see the official documentation.

Worksheet Versioning

Inspired by a snowflake developers maintained repository.

Git integration

The extension is designed to apply git versioning on worksheets while developing on Snowsight, fully taking advantage of its functionalities.
The following workflow is advised :

  1. [Start session] Upload worksheet from local branch to a user Snowsight workspace
  2. Test, update and validate on Snowsight
  3. [End session] Update local branch with modified Snowsight worksheets

Install

Entry points are accessible through a CLI once the package is installed. To install it, please follow the following steps :

# [Optional: Python virtual environement]
$ pyenv virtualenv 3.10.4 sf
$ pyenv activate sf

# [Mandatory: Pip install]
$ pip install -U pip
$ pip install sf_git==1.4.0

# [Check your installation]
$ sfgit --version
# [Should result in:]
# sfgit, version 1.4.0


# [Check your installation]
$ sfgit --help

# [Should result in:]
# Usage: sfgit [OPTIONS] COMMAND [ARGS]...
# 
# Options:
#   --help  Show this message and exit.
# 
# Commands:
#   commit  Commit Snowsight worksheets to Git repository.
#   config  Configure sfgit for easier version control.
#   fetch   Fetch worksheets from user Snowsight account and store them in...
#   init    Initialize a git repository and set it as the sfgit versioning...
#   push    Upload locally stored worksheets to Snowsight user workspace.

Commands have been created to import/export (respectively fetch/push) snowsight worksheets to/from local.

Configure your git

Warning A git repository is necessary to manage worksheets. You can either use an existing one or create a new one.

To apply versioning to your worksheets, you need to configure Git information through the config command.

First, set git repository to be used:

# if you want to use an existing git repository
$ sfgit config --git-repo <path_to_git_repo>

# if you want to create a new one 
$ sfgit init -p <path_to_git_repo>

Then, set a location to save your worksheets within this git repository:

$ sfgit config --save-dir <path_to_worksheets_persistency_directory>

Authenticate

Currently, only authentication mode supported is the credentials (PWD) mode.

:warning: The single sign-on (SSO) will be fixed.

Commands requiring Snowsight authentication all have options to provide at command time. If you don't want to manually input them everytime, you can set them at Python/Virtual environement level with :

$ sfgit config --account <your_snowsight_account_id>
$ sfgit config --username <your_snowsight_login_name>
$ sfgit config --password <your_snowsight_password>  # unnecessary for SSO authentication mode

Account ID

[!WARNING]
The account ID to be configured is in the <account_name>.<region>.<cloud> format.

If you are unsure about how to retrieve it for your snowflake account, you can run this query:

SHOW REGIONS;

WITH 
    SF_REGIONS AS (SELECT * FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))),
    INFOS AS (SELECT CURRENT_REGION() AS CR, CURRENT_ACCOUNT() AS CA)
SELECT CONCAT(
        LOWER(INFOS.CA),
        '.',
        SF_REGIONS."region",
        '.',
        SF_REGIONS."cloud"
    ) AS account_id
FROM INFOS LEFT JOIN SF_REGIONS ON INFOS.CR = SF_REGIONS."snowflake_region";

Unfortunately, the region is not always the same in the SHOW REGIONS ouput. Please check and adapt the format comforming to the official documentation. For example, eastus2 for Azure should actually be east-us-2.

Use

Import user worksheet locally :

$ sfgit fetch --auth-mode PWD

Import user worksheet locally (using command time args) :

$ sfgit fetch --username tdambrin --account-id my_account.west-europe.azure -p mysecret -am PWD

See what changed for only your worksheets in the git :

$ sfgit diff

Commit you worksheets (or through git commands for more flexibility) :

$ sfgit commit --branch master -m "Initial worksheet commit"

Export user worksheets to Snowsight

$ sfgit push --auth-mode PWD --branch master

Be creative

Use the package to fit your use case, versioning is a way to do many things.

Switch versions

Switch versions

Transfer worksheets to another account

Transfer accounts

Policies

Feedbacks and contributions are greatly appreciated. This package was made to ease every day life for Snowflake developers and promote version control as much as possible.

For questions, please feel free to reach out by email.

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

sf_git-1.4.0.tar.gz (373.3 kB view details)

Uploaded Source

Built Distribution

sf_git-1.4.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file sf_git-1.4.0.tar.gz.

File metadata

  • Download URL: sf_git-1.4.0.tar.gz
  • Upload date:
  • Size: 373.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.4

File hashes

Hashes for sf_git-1.4.0.tar.gz
Algorithm Hash digest
SHA256 37436776557c66df9452339bfd2ffd25cc1c8d94c7788647c02ac81d7b33ee87
MD5 13300af8cd9f08d83c879b8ece7235df
BLAKE2b-256 424078334b83466ba628f3868cbf94b909d3bb4b2243a3c8f5e15a97fa54d03b

See more details on using hashes here.

File details

Details for the file sf_git-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: sf_git-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.4

File hashes

Hashes for sf_git-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33230574918f8a97cf0e13c38884996c8560eab29d6e6f995ea4d25e55bbe52c
MD5 929b2246f14c2f1117b5e9b6e0ed3fea
BLAKE2b-256 28d9d0317750e65445dc11f79b0dfa893711351f5452ecf4c1b58811960f3ff3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page