shipyard-snowflake


Nameshipyard-snowflake JSON
Version 0.2.7 PyPI version JSON
download
home_pageNone
SummaryA local client for conecting and working with Snowflake
upload_time2024-05-03 14:38:51
maintainerNone
docs_urlNone
authorwrp801
requires_python<3.11,>=3.9
licenseApache 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # shipyard-snowflake

The `shipyard-snowflake` Python Package is a set of utility classes designed to streamline interactions with Snowflake, a cloud-based data warehousing platform. This package offers two main client classes, `SnowflakeClient` and `SnowparkClient`, each catering to different use cases and functionalities within the Snowflake ecosystem.

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
  - [SnowflakeClient](#snowflakeclient)
  - [SnowparkClient](#snowparkclient)
## Installation

You can install `shipyard-snowflake` using `pip`:

```bash
python3 -m pip install shipyard-snowflake
```

## Usage

### SnowflakeClient

The SnowflakeClient class provides methods to interact with Snowflake using the Snowflake Python Connector. It supports functionalities such as authentication, data uploading, executing queries, and fetching results. Here's an example of how to use it:

```python
import pandas as pd
from shipyard_snowflake import SnowflakeClient
from shipyard_snowflake.utils import utils
# Initialize the SnowflakeClient with credentials
client = SnowflakeClient(
    username="your_username",
    pwd="your_password",
    account="your_account_id",
    warehouse="your_warehouse",
    database="your_database",
    schema="your_schema",
    rsa_key="your_rsa_key",  # Optional, use either rsa_key or pwd
    role="your_role"
)

# Connect to Snowflake
client.connect()
```


### Upload a file to Create or Replace a Table 
```python 

# Upload a csv to Snowflake to replace a table
# create the table first
data_types = utils.infer_schema(file_name = "<file_path>")
sql = client._create_table_sql(table_name = "<table_name>", columns = data_types)
client.create_table(sql)
# load the file to the table
client.upload(file_path = "<file_path>", table_name = "<table_name>", insert_method = "replace")

``` 
### Upload a file to append to an existing table 
```python
client.upload(file_path = "<file_path>", table_name = "<table_name>", insert_method = "append")

### Fetch the results of a query as a pandas dataframe
```python
query = "SELECT * FROM your_table_name"
result_df = client.execute_query(query=query)
```

### Execute a Query
```python
query = "DROP TABLE IF EXISTS SALES"
result_df = client.fetch(query = query)
```

### Close the connection 
```python
# Close the connection
client.conn.close()
```

### SnowparkClient

The SnowparkClient class allows interaction with Snowflake using Snowpark, a modern data processing and scripting framework. It enables data upload and some query execution capabilities. Here's an example of how to use it:
```python
from shipyard_snowflake import SnowparkClient

# Initialize the SnowparkClient with credentials
client = SnowparkClient(
    username="your_username",
    pwd="your_password",
    account="your_account_url",
    warehouse="your_warehouse", # optional
    database="your_database", # optional
    schema="your_schema", # optional
    role="your_role" # optional
)

# Connect to Snowflake using Snowpark
session = client.connect()

# Upload a DataFrame to Snowflake
import pandas as pd
df = pd.DataFrame(...)  # Your DataFrame
client.upload(
    session=session,
    df=df,
    table_name="your_table_name",
    overwrite=True # False for append
)
# Close the session
session.close()
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "shipyard-snowflake",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.11,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "wrp801",
    "author_email": "wespoulsen@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6f/c7/4af049652dc919352d786f60a3eae5926c88d98725a5faa8f50247b940b8/shipyard_snowflake-0.2.7.tar.gz",
    "platform": null,
    "description": "# shipyard-snowflake\n\nThe `shipyard-snowflake` Python Package is a set of utility classes designed to streamline interactions with Snowflake, a cloud-based data warehousing platform. This package offers two main client classes, `SnowflakeClient` and `SnowparkClient`, each catering to different use cases and functionalities within the Snowflake ecosystem.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [SnowflakeClient](#snowflakeclient)\n  - [SnowparkClient](#snowparkclient)\n## Installation\n\nYou can install `shipyard-snowflake` using `pip`:\n\n```bash\npython3 -m pip install shipyard-snowflake\n```\n\n## Usage\n\n### SnowflakeClient\n\nThe SnowflakeClient class provides methods to interact with Snowflake using the Snowflake Python Connector. It supports functionalities such as authentication, data uploading, executing queries, and fetching results. Here's an example of how to use it:\n\n```python\nimport pandas as pd\nfrom shipyard_snowflake import SnowflakeClient\nfrom shipyard_snowflake.utils import utils\n# Initialize the SnowflakeClient with credentials\nclient = SnowflakeClient(\n    username=\"your_username\",\n    pwd=\"your_password\",\n    account=\"your_account_id\",\n    warehouse=\"your_warehouse\",\n    database=\"your_database\",\n    schema=\"your_schema\",\n    rsa_key=\"your_rsa_key\",  # Optional, use either rsa_key or pwd\n    role=\"your_role\"\n)\n\n# Connect to Snowflake\nclient.connect()\n```\n\n\n### Upload a file to Create or Replace a Table \n```python \n\n# Upload a csv to Snowflake to replace a table\n# create the table first\ndata_types = utils.infer_schema(file_name = \"<file_path>\")\nsql = client._create_table_sql(table_name = \"<table_name>\", columns = data_types)\nclient.create_table(sql)\n# load the file to the table\nclient.upload(file_path = \"<file_path>\", table_name = \"<table_name>\", insert_method = \"replace\")\n\n``` \n### Upload a file to append to an existing table \n```python\nclient.upload(file_path = \"<file_path>\", table_name = \"<table_name>\", insert_method = \"append\")\n\n### Fetch the results of a query as a pandas dataframe\n```python\nquery = \"SELECT * FROM your_table_name\"\nresult_df = client.execute_query(query=query)\n```\n\n### Execute a Query\n```python\nquery = \"DROP TABLE IF EXISTS SALES\"\nresult_df = client.fetch(query = query)\n```\n\n### Close the connection \n```python\n# Close the connection\nclient.conn.close()\n```\n\n### SnowparkClient\n\nThe SnowparkClient class allows interaction with Snowflake using Snowpark, a modern data processing and scripting framework. It enables data upload and some query execution capabilities. Here's an example of how to use it:\n```python\nfrom shipyard_snowflake import SnowparkClient\n\n# Initialize the SnowparkClient with credentials\nclient = SnowparkClient(\n    username=\"your_username\",\n    pwd=\"your_password\",\n    account=\"your_account_url\",\n    warehouse=\"your_warehouse\", # optional\n    database=\"your_database\", # optional\n    schema=\"your_schema\", # optional\n    role=\"your_role\" # optional\n)\n\n# Connect to Snowflake using Snowpark\nsession = client.connect()\n\n# Upload a DataFrame to Snowflake\nimport pandas as pd\ndf = pd.DataFrame(...)  # Your DataFrame\nclient.upload(\n    session=session,\n    df=df,\n    table_name=\"your_table_name\",\n    overwrite=True # False for append\n)\n# Close the session\nsession.close()\n```\n\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "A local client for conecting and working with Snowflake",
    "version": "0.2.7",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9562d45db2655bad5fb4c8beca19e075e4f206a12242ab557d233ef3981b056c",
                "md5": "9c5d3b6a3fb1fd83641a4928fb5cccff",
                "sha256": "a1af8cf4f01e6b7f3e498622255de3123e94cc73eb861a5fe8547d5bf3082c39"
            },
            "downloads": -1,
            "filename": "shipyard_snowflake-0.2.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9c5d3b6a3fb1fd83641a4928fb5cccff",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.11,>=3.9",
            "size": 18672,
            "upload_time": "2024-05-03T14:38:49",
            "upload_time_iso_8601": "2024-05-03T14:38:49.656741Z",
            "url": "https://files.pythonhosted.org/packages/95/62/d45db2655bad5fb4c8beca19e075e4f206a12242ab557d233ef3981b056c/shipyard_snowflake-0.2.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6fc74af049652dc919352d786f60a3eae5926c88d98725a5faa8f50247b940b8",
                "md5": "483d49d3e22fa324392b0411122b48de",
                "sha256": "8fe3bf8c2b55907e1b885b0df84a5065d2e0c2b195f421ef694fe118a7546eaf"
            },
            "downloads": -1,
            "filename": "shipyard_snowflake-0.2.7.tar.gz",
            "has_sig": false,
            "md5_digest": "483d49d3e22fa324392b0411122b48de",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.11,>=3.9",
            "size": 13741,
            "upload_time": "2024-05-03T14:38:51",
            "upload_time_iso_8601": "2024-05-03T14:38:51.385340Z",
            "url": "https://files.pythonhosted.org/packages/6f/c7/4af049652dc919352d786f60a3eae5926c88d98725a5faa8f50247b940b8/shipyard_snowflake-0.2.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-03 14:38:51",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "shipyard-snowflake"
}
        
Elapsed time: 0.25206s