How to connect Python with Snowflake

Hoda Saiful
2 min readSep 13, 2021

This article illustrates

  1. How to connect Python (Jupyter Notebook) with Snowflake Database.
  2. Retrieve the results of SQL into a Pandas Data Frame.

Once the data is in a Pandas Data Frame, any operation supported by Pandas can be formed on the data set.

Software Requirements

  1. A table in Snowflake database with some data in it
  2. User Name, Password and Host details of the Snowflake database
  3. Jupyter notebook
  4. Familiarity with Python and programming constructs.

Procedure:

1. Install dependencies

The Snowflake Connector for Python provides an interface for developing Python applications that can connect to Snowflake and perform all standard operations. The connector can currently be installed in Linux, macOS, and Windows environments.The package required to connect Snowflake with python is snowflake-connector-python. The package can be installed using a python PIP installer. Since we are using Jupyter, we run all commands on Jupyter web interface.

The required package is now available in the local python Eco-system

2. Set up a configuration file

The configuration details required are User Name, Password and host name of the database

I’ve created a nested dictionary with the top most level key as connection name. I’ve wrapped the connection details as a key value pair. In future if there are more connections, the same configuration file could be utilized.

3. Create a connection

4. Take the Connection for a spin

READ_SQL is an inbuilt function in Pandas package that reads SQL query or database table into a pandas Data Frame.

--

--