Skip to content

Commit 04af80e

Browse files
committed
Add improt from folder example
1 parent fab8e96 commit 04af80e

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ Each folder in this repo contains a new hack for running a data science team usi
1212

1313
### [Version Control Deployment](https://github.com/blackary/sis-tricks/tree/main/deploy-branches)
1414

15+
### [Importing from Folder](https://github.com/blackary/sis-tricks/tree/main/import-from-folder)
16+
1517
## Help:
16-
If you have issues with any of these, or want to get into the SiS PrPr, please reach out to your Snowflake representative.
18+
19+
If you have issues with any of these, or want to get into the SiS PrPr, please reach out to your Snowflake representative.

import-from-folder/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Import from folder
2+
3+
If you have a folder full of modules that you want to import from your app, than
4+
the trick from [Multiple python files](https://github.com/blackary/sis-tricks/tree/main/multiple-python-files)
5+
won't work -- you can't just `put` a whole folder to the stage and then import from it.
6+
7+
Instead, you can create a zip folder, put _that_ to the stage, and then import from
8+
that zip directly.
9+
10+
1. Create an app with the code from streamlit_app.py
11+
2. Put several python modules in the `utils` folder, or another similar
12+
3. Zip the utils folder
13+
14+
```sh
15+
zip -r utils.zip utils/*.py
16+
```
17+
18+
4. Create the app in SiS, either through the web UI, or through the snowcli
19+
20+
```sh
21+
snow streamlit create --file streamlit_app.py GREAT_NAME_FOR_MY_STREAMLIT
22+
snow streamlit deploy --file streamlit_app.py GREAT_NAME_FOR_MY_STREAMLIT
23+
```
24+
25+
5. Upload utils.zip to the stage
26+
27+
```sh
28+
snow stage put utils.zip GREAT_NAME_FOR_MY_STREAMLIT_STAGE
29+
```
30+
31+
6. Profit!

import-from-folder/streamlit_app.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import sys
2+
3+
sys.path.append("utilt.zip")
4+
5+
# If the folder 'utils' exists, then this will import from that folder. Otherwise
6+
# it will import from the zip file.
7+
from utils.plotting import this_is_a_cool_function
8+
9+
this_is_a_cool_function()

import-from-folder/utils/plotting.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def this_is_a_cool_function():
2+
pass

0 commit comments

Comments
 (0)