Soumil Nitin Shah¶
Bachelor in Electronic Engineering | Masters in Electrical Engineering | Master in Computer Engineering |
- Website : https://soumilshah.herokuapp.com
- Github: https://github.com/soumilshah1995
- Linkedin: https://www.linkedin.com/in/shah-soumil/
- Blog: https://soumilshah1995.blogspot.com/
- Youtube : https://www.youtube.com/channel/UC_eOodxvwS_H7x2uLQa-svw?view_as=subscriber
- Facebook Page : https://www.facebook.com/soumilshah1995/
- Email : shahsoumil519@gmail.com
- projects : https://soumilshah.herokuapp.com/project
Hello! I’m Soumil Nitin Shah, a Software and Hardware Developer based in New York City. I have completed by Bachelor in Electronic Engineering and my Double master’s in Computer and Electrical Engineering. I Develop Python Based Cross Platform Desktop Application , Webpages , Software, REST API, Database and much more I have more than 2 Years of Experience in Python
Welcome We will be Learning about GCP Buckets¶
# pip install --upgrade google-api-python-client
# pip install --upgrade google-cloud-storage
# https://cloud.google.com/storage/docs/reference/libraries?authuser=1#client-libraries-install-python
Make sure to download the Keys¶
try:
from google.cloud import storage
import google.cloud.storage
import json
import os
import sys
except Exception as e:
print("Error : {} ".format(e))
PATH = os.path.join(os.getcwd() , 'propane-calling-262419-9f249a3aa132.json')
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = PATH
- Create a Client Object
storage_client = storage.Client(PATH)
storage_client
Getting all Files from GCP Bucket¶
bucket = storage_client.get_bucket('myfirst-bucket-1995')
filename = [filename.name for filename in list(bucket.list_blobs(prefix='')) ]
filename
Downloading a File from Bucket¶
blop = bucket.blob(blob_name = 'netflix_titles.csv').download_as_string()
with open ('doo.csv', "wb") as f:
f.write(blop)
Pushing a file on GCP bucket¶
filename= 'doo.csv'
UPLOADFILE = os.path.join(os.getcwd(), filename)
bucket = storage_client.get_bucket('myfirst-bucket-1995')
blob = bucket.blob(filename)
blob.upload_from_filename(UPLOADFILE)
Reading CSV File Drieectly from GCP bucket¶
import pandas as pd
import io
from io import BytesIO
df = pd.read_csv(
io.BytesIO(
bucket.blob(blob_name = 'netflix_titles.csv').download_as_string()
) ,
encoding='UTF-8',
sep=',')
df.head(1)
Deleting a file from GCP bucket¶
filename = [filename.name for filename in list(bucket.list_blobs(prefix='')) ]
filename
DELETE_FILE = 'doo.csv'
bucket = storage_client.get_bucket('myfirst-bucket-1995')
blob = bucket.blob(DELETE_FILE)
blob.delete()
filename = [filename.name for filename in list(bucket.list_blobs(prefix='')) ]
filename