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 2 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
34 changes: 34 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,40 @@ models:

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

#### Third-party snowflake packages
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

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) then, configure `imports` in the dbt Python model to reference to the zip file in your Snowflake staging.
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

Here’s a complete example configuration, including using `imports` in a Python model:
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

```python

import sys
from snowflake.snowpark.types import StructType, FloatType, StringType, StructField

def model( dbt, session):

dbt.config(
materialized='table',
imports = ['@dbt_integration_test/iris.csv'],
use_anonymous_sproc = False
)
schema_for_data_file = StructType([
StructField("length1", FloatType()),
StructField("width1", FloatType()),
StructField("length2", FloatType()),
StructField("width2", FloatType()),
StructField("variety", StringType()),
])
df = session.read.schema(schema_for_data_file).option("field_delimiter", ",").schema(schema_for_data_file).csv("@dbt_integration_test/iris.csv")
return df

```

In this example, dbt is configured to locate the `iris.csv` file in the designated Snowflake stage, `@dbt_integration_test`.
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

For more information on using this configuration, refer to [test_python_model.py](https://github.com/dbt-labs/dbt-snowflake/blob/1d299923e34c96f2e96a5215ac196658f86ce1d1/tests/functional/adapter/test_python_model.py#L90).

</div>

<div warehouse="Databricks">
Expand Down
Loading