Integration between Python/FastAPI and Snowflake

pip install fastapipip install uvicorn
create or replace stage first_stage
file_format = (type = 'CSV' field_delimiter = ',' skip_header = 1);
create table Customers(CustomerID int, LastName varchar(20) ,FirstName varchar(20),Products varchar(30),Category varchar(15));
INSERT INTO Customers(CustomerID, LastName, FirstName, Products, Category)VALUES ('2', 'Maheshwarappa', 'Abhishek', 'OnePlus', 'Mobile');
select * from Customers;
create or replace procedure read_customer_proc() 
returns String not null
language javascript
var my_sql_command = "select * from Customers";var statement1 = snowflake.createStatement( {sqlText: my_sql_command} ); var result_set1 = statement1.execute();while( { var column1 = result_set1.getColumnValue(1);
var column2 = result_set1.getColumnValue(2);
var column3 = result_set1.getColumnValue(3);
var column4 = result_set1.getColumnValue(4);
var column5 = result_set1.getColumnValue(5);
var column = column1+' '+column2+' '+column3+' '+column4+' '+column5 } return column;
call read_person_proc();
from fastapi import FastAPIimport snowflake.connector as sfusername='<username>'
app = FastAPI()@app.get('/fetchdata')async def fetchdata():
cursor = ctx.cursor()
cursor.execute("USE WAREHOUSE COMPUTE_WH ")
cursor.execute("USE DATABASE FIRST")
cursor.execute("USE schema PUBLIC")
sql = cursor.execute("call read_customer_proc()")
for data in sql:
return data
uvicorn main:app --reload




Data Scientist | ML-Ops| | |

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Step-by-step guide on How to get Game Token Airdrop in Klaytn Games

Python Libraries For Data Science : DAY-5 →Matplotlib (HistogramsGraph)

How I use Tkinter Python Library to Run Algorithms

Restoring MongoDB Replica Set Case Study

Nate Bot Rewrite

I grabbed a Twitter handle and tweeted my intention.

DevOps, or Dev vs Ops

NVIDIA Jetson Nano: Communication with industrial PLC using OPC UA

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhishek Maheshwarappa

Abhishek Maheshwarappa

Data Scientist | ML-Ops| | |

More from Medium

How to Make Robust EMR on EKS pipelines + Airflow

Collapsing Multiline Logs in Spark

Docker, Spark, and Iceberg: The Fastest Way to Try Iceberg!

Close up photo of a penguin swimming in the ocean.

A Short Introduction to Apache Iceberg