Saturday, July 24, 2021

Write to GCP from python

 Source:

https://dzone.com/articles/upload-files-to-google-cloud


First install python library


pip install google-cloud-storage



The Credentials

Accessing GCS through Python API requires credentials to be stored locally on your system in a JSON file format, which can be downloaded from the IAM and Admin service.

It requires the creation of a new service account.

New service account

The Code

Python

1
2
from google.cloud import storage
3
4
# Setting credentials using the downloaded JSON file
5
client = storage.Client.from_service_account_json(json_credentials_path='credentials-python-storage.json')
6
7
# Creating bucket object
8
bucket = client.get_bucket('py-python')
9
10
# Name of the object to be stored in the bucket
11
object_name_in_gcs_bucket = bucket.blob('my_first_gcs_upload.png')
12
13
# Name of the object in local file system
14
object_name_in_gcs_bucket.upload_from_filename('gcs.png')



Bucket details


Loud fan of desktop

 Upon restart the fan of the desktop got loud again. I cleaned the desktop from the dust but it was still loud (Lower than the first sound) ...