sf-git


Namesf-git JSON
Version 1.4.2 PyPI version JSON
download
home_pagehttps://github.com/tdambrin/sf_git
SummaryPython package to manipulate Snowsight worksheets
upload_time2024-10-11 18:30:12
maintainerNone
docs_urlNone
authorThomas Dambrin
requires_pythonNone
licenseMIT
keywords python snowflake git
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            <p align="center">
  <img src="https://github.com/tdambrin/sf_git/assets/61944454/077aa882-95c2-4f61-a05d-64e8e156b266" alt="sfgit logo" width="30%">
</p>

![image](https://img.shields.io/badge/Python-FFD43B?style=for-the-badge&logo=python&logoColor=blue)
[![image](https://img.shields.io/badge/Gmail-D14836?style=for-the-badge&logo=gmail&logoColor=white)](mailto:thomas.dambrin@gmail.com?subject=[GitHub]%20Snowflake%20Git%20Versioning)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/tdambrin/e2c293d7db07bee70d2845387cb133ff/raw/sf_git_main_cov_badge.json)



# Snowflake Git

🆕 Git now supported in Snowflake, see the [official documentation](https://docs.snowflake.com/en/developer-guide/git/git-overview).

# Worksheet Versioning

Inspired by a snowflake developers maintained [repository](https://github.com/Snowflake-Labs/sfsnowsightextensions).

### 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 :

```bash
# [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.2

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


# [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:

```bash
# 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:
```bash
$ 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 :


```bash
$ 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:

```sql
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](https://docs.snowflake.com/en/user-guide/admin-account-identifier#non-vps-account-locator-formats-by-cloud-platform-and-region).
For example, eastus2 for Azure should actually be east-us-2.


## Use

**Import user worksheet locally** :
```bash
$ sfgit fetch --auth-mode PWD
```

**Import user worksheet locally (using command time args)** :
```bash
$ 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** :
```bash
$ sfgit diff
```

**Commit you worksheets** (or through git commands for more flexibility) :
```bash
$ sfgit commit --branch master -m "Initial worksheet commit"
```

**Export user worksheets to Snowsight** 
```bash
$ 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

<div align="center">
    <img src="./doc/images/switch_versions.png" alt="Switch versions" width="70%"/>
</div>


### Transfer worksheets to another account

![Transfer accounts](./doc/images/transfer_accounts.png)

## 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](mailto:thomas.dambrin@gmail.com?subject=[GitHub]%20Snowflake%20Git%20Versioning).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/tdambrin/sf_git",
    "name": "sf-git",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "python, snowflake, git",
    "author": "Thomas Dambrin",
    "author_email": "thomas.dambrin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/80/c4/43b266cde383969f1b7cb4ab8371e4e3188710b089538ac63c0d2bc90eda/sf_git-1.4.2.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <img src=\"https://github.com/tdambrin/sf_git/assets/61944454/077aa882-95c2-4f61-a05d-64e8e156b266\" alt=\"sfgit logo\" width=\"30%\">\n</p>\n\n![image](https://img.shields.io/badge/Python-FFD43B?style=for-the-badge&logo=python&logoColor=blue)\n[![image](https://img.shields.io/badge/Gmail-D14836?style=for-the-badge&logo=gmail&logoColor=white)](mailto:thomas.dambrin@gmail.com?subject=[GitHub]%20Snowflake%20Git%20Versioning)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/tdambrin/e2c293d7db07bee70d2845387cb133ff/raw/sf_git_main_cov_badge.json)\n\n\n\n# Snowflake Git\n\n\ud83c\udd95 Git now supported in Snowflake, see the [official documentation](https://docs.snowflake.com/en/developer-guide/git/git-overview).\n\n# Worksheet Versioning\n\nInspired by a snowflake developers maintained [repository](https://github.com/Snowflake-Labs/sfsnowsightextensions).\n\n### Git integration \n\nThe extension is designed to **apply git versioning on worksheets while developing on Snowsight, fully taking advantage of its functionalities**.\\\nThe following workflow is advised :\n1. [Start session] Upload worksheet from local branch to a user Snowsight workspace\n2. Test, update and validate on Snowsight \n3. [End session] Update local branch with modified Snowsight worksheets\n\n## Install\n\nEntry points are accessible through a CLI once the package is installed. \nTo install it, please follow the following steps :\n\n```bash\n# [Optional: Python virtual environement]\n$ pyenv virtualenv 3.10.4 sf\n$ pyenv activate sf\n\n# [Mandatory: Pip install]\n$ pip install -U pip\n$ pip install sf_git==1.4.2\n\n# [Check your installation]\n$ sfgit --version\n# [Should result in:]\n# sfgit, version 1.4.2\n\n\n# [Check your installation]\n$ sfgit --help\n\n# [Should result in:]\n# Usage: sfgit [OPTIONS] COMMAND [ARGS]...\n# \n# Options:\n#   --help  Show this message and exit.\n# \n# Commands:\n#   commit  Commit Snowsight worksheets to Git repository.\n#   config  Configure sfgit for easier version control.\n#   fetch   Fetch worksheets from user Snowsight account and store them in...\n#   init    Initialize a git repository and set it as the sfgit versioning...\n#   push    Upload locally stored worksheets to Snowsight user workspace.\n```\n\nCommands have been created to **import/export (respectively fetch/push) snowsight worksheets to/from local**.\n\n## Configure your git\n\n> **Warning**\n> A git repository is necessary to manage worksheets. You can either use an existing one\n> or create a new one.\n\nTo apply versioning to your worksheets, you need to **configure Git information**\nthrough the config command. \n\nFirst, set git repository to be used:\n\n```bash\n# if you want to use an existing git repository\n$ sfgit config --git-repo <path_to_git_repo>\n\n# if you want to create a new one \n$ sfgit init -p <path_to_git_repo>\n```\n\nThen, set a location to save your worksheets within this git repository:\n```bash\n$ sfgit config --save-dir <path_to_worksheets_persistency_directory>\n```\n\n## Authenticate\nCurrently, only authentication mode supported is the credentials (PWD) mode.\n\n> :warning: The single sign-on (SSO) will be fixed.\n\nCommands requiring Snowsight authentication all have options to provide at command time. \nIf you don't want to manually input them everytime, you can set them at Python/Virtual environement level with :\n\n\n```bash\n$ sfgit config --account <your_snowsight_account_id>\n$ sfgit config --username <your_snowsight_login_name>\n$ sfgit config --password <your_snowsight_password>  # unnecessary for SSO authentication mode\n```\n\n### Account ID\n\n> [!WARNING]  \n> `The account ID to be configured is in the <account_name>.<region>.<cloud> format.`\n\nIf you are unsure about how to retrieve it for your snowflake account, you can run this query:\n\n```sql\nSHOW REGIONS;\n\nWITH \n    SF_REGIONS AS (SELECT * FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))),\n    INFOS AS (SELECT CURRENT_REGION() AS CR, CURRENT_ACCOUNT() AS CA)\nSELECT CONCAT(\n        LOWER(INFOS.CA),\n        '.',\n        SF_REGIONS.\"region\",\n        '.',\n        SF_REGIONS.\"cloud\"\n    ) AS account_id\nFROM INFOS LEFT JOIN SF_REGIONS ON INFOS.CR = SF_REGIONS.\"snowflake_region\";\n\n```\n\nUnfortunately, the _region_ is not always the same in the _SHOW REGIONS_ ouput. Please check and adapt the format comforming to the official [documentation](https://docs.snowflake.com/en/user-guide/admin-account-identifier#non-vps-account-locator-formats-by-cloud-platform-and-region).\nFor example, eastus2 for Azure should actually be east-us-2.\n\n\n## Use\n\n**Import user worksheet locally** :\n```bash\n$ sfgit fetch --auth-mode PWD\n```\n\n**Import user worksheet locally (using command time args)** :\n```bash\n$ sfgit fetch --username tdambrin --account-id my_account.west-europe.azure -p mysecret -am PWD\n```\n\n**See what changed for only your worksheets in the git** :\n```bash\n$ sfgit diff\n```\n\n**Commit you worksheets** (or through git commands for more flexibility) :\n```bash\n$ sfgit commit --branch master -m \"Initial worksheet commit\"\n```\n\n**Export user worksheets to Snowsight** \n```bash\n$ sfgit push --auth-mode PWD --branch master\n```\n\n## Be creative\n\nUse the package to fit your use case, versioning is a way to do many things.\n\n### Switch versions\n\n<div align=\"center\">\n    <img src=\"./doc/images/switch_versions.png\" alt=\"Switch versions\" width=\"70%\"/>\n</div>\n\n\n### Transfer worksheets to another account\n\n![Transfer accounts](./doc/images/transfer_accounts.png)\n\n## Policies\nFeedbacks and contributions are greatly appreciated. This package was made to ease every day life for Snowflake \ndevelopers and promote version control as much as possible.\n\nFor questions, please feel free to reach out [by email](mailto:thomas.dambrin@gmail.com?subject=[GitHub]%20Snowflake%20Git%20Versioning).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python package to manipulate Snowsight worksheets",
    "version": "1.4.2",
    "project_urls": {
        "Homepage": "https://github.com/tdambrin/sf_git"
    },
    "split_keywords": [
        "python",
        " snowflake",
        " git"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3c7231423a824e14af42b5f5564d7dd93050cca25ad01e928d2bbb6a19aebe50",
                "md5": "a7afbd3e2c53130f946a77c5a45e4bec",
                "sha256": "63e43562014e84ce2f91d7844ea4f8a6519453abdad66b3c093ba97b3cd20d2e"
            },
            "downloads": -1,
            "filename": "sf_git-1.4.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a7afbd3e2c53130f946a77c5a45e4bec",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 22513,
            "upload_time": "2024-10-11T18:30:10",
            "upload_time_iso_8601": "2024-10-11T18:30:10.329113Z",
            "url": "https://files.pythonhosted.org/packages/3c/72/31423a824e14af42b5f5564d7dd93050cca25ad01e928d2bbb6a19aebe50/sf_git-1.4.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "80c443b266cde383969f1b7cb4ab8371e4e3188710b089538ac63c0d2bc90eda",
                "md5": "a3c3fbcf60bcee4ef7c74322a3a66b56",
                "sha256": "99f14d21bddc2b8ad6230804cf30af5aa3d5c66d3ec0f263566595540b37f44c"
            },
            "downloads": -1,
            "filename": "sf_git-1.4.2.tar.gz",
            "has_sig": false,
            "md5_digest": "a3c3fbcf60bcee4ef7c74322a3a66b56",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 373416,
            "upload_time": "2024-10-11T18:30:12",
            "upload_time_iso_8601": "2024-10-11T18:30:12.058522Z",
            "url": "https://files.pythonhosted.org/packages/80/c4/43b266cde383969f1b7cb4ab8371e4e3188710b089538ac63c0d2bc90eda/sf_git-1.4.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-11 18:30:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tdambrin",
    "github_project": "sf_git",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "sf-git"
}
        
Elapsed time: 0.62489s