Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added section to Python models doc to discuss third party packages following this the thread: https://dbt-labs.slack.com/archives/C05FWBP9X1U/p1730272033637189 #6418

Merged
merged 16 commits into from
Nov 12, 2024
Merged
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions website/docs/docs/build/python-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,41 @@ models:

**Docs:** ["Developer Guide: Snowpark Python"](https://docs.snowflake.com/en/developer-guide/snowpark/python/index.html)

#### Third-party Snowflake packages

To use a third-party Snowflake package that isn't available in Snowflake Anaconda, upload your package by following [this example](https://docs.snowflake.com/en/developer-guide/udf/python/udf-python-packages#importing-packages-through-a-snowflake-stage), and then configure the `imports` setting in the dbt Python model to reference to the zip file in your Snowflake staging.

Here’s a complete example configuration using a zip file, including using `imports` in a Python model:

```python

def model(dbt, session):
# Configure the model
dbt.config(
materialized="table",
imports=["@mystage/mycustompackage.zip"], # Specify the external package location
)

# Example data transformation using the imported package
# (Assuming `some_external_package` has a function we can call)
data = {
"name": ["Alice", "Bob", "Charlie"],
"score": [85, 90, 88]
}
df = pd.DataFrame(data)

# Process data with the external package
df["adjusted_score"] = df["score"].apply(lambda x: some_external_package.adjust_score(x))

# Return the DataFrame as the model output
return df

```

For more information on using this configuration, refer to [Snowflake's documentation](https://community.snowflake.com/s/article/how-to-use-other-python-packages-in-snowpark) on uploading and using other python packages in Snowpark not published on Snowflake's Anaconda channel.

To use external libraries, you can also use the [`zip`](https://github.com/phdata/dbt_snowpark_sentiment_example/blob/2c5528278e14dba678fb7773cca2d47f8adbeb4d/models/reviews.py#L30) approach.
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

</div>

<div warehouse="Databricks">
Expand Down
Loading