Simple example of connecting to Snowflake and executing a query using Python and sqla-raw.
Once dependencies are properly installed and $DATABASE_URL configured in the environment, snowflake-sample-query.py prints out the 10 most recently created users as a list of dictionaries with id, created_at, email, and name of each user.
For Jupyter notebook users, snowflake-sample-notebook.ipynb provides the same results as tabular display from a Pandas DataFrame.
git clonethis repo andcdinto working directory- create virtual environment and install dependencies:
$ python -m venv .venv
$ source /.venv/bin/activate
$ python -m pip install -r requirements.txt
- copy
.env.exampleto.envand edit with appropriate username and password values - source the
.envfile to set$DATABASE_URLin the environment:set -a; source .env; set +a - run
python snowflake-sample-query.py🎉
-
Follow installation above
-
Ensure
$DATABASE_URLis set in the local environment:set -a; source .env; set +a- Alternatively, set the connection URL inline and call
db.engine()as described in comments in the sample notebook itself
- Alternatively, set the connection URL inline and call
-
open your Jupyter server from there
$ ipython kernel install --user --name=.venv $ jupyter notebook- Or otherwise choose
example-python-snowflake-project/.venvas your active Jupyter kernel - Or use whatever kernel is most convenient, and ensure
sqla-rawandsnowflake-sqlalchemylibraries are installed within your kernel
- Or otherwise choose
-
Open
snowflake-sample-notebook.ipynbin Jupyter -
Run all cells and see result of query in table at the end! 🎉