I often find myself reuuing the same bits of code when working with GCP. It is very important to avoid creating multiple development trees of the same classes. I have done this before for large projects. It will lead to a very difficult to maintain stack of tools that will spaghettify over time.
mkdir gcpuptils
github link to latest file is the link to the gcpclient.py
file on GitHub.
- Run
git init && git add . && git commit -m 'init'
- run
gh repo create
and follow the prompts - run
git push
and follow the prompts
In my example i created a repo at https://github.com/justin-napolitano/gcputils.git
to importrun git submodule add -b pit https://github.com/justin-napolitano/gcputils.git
to import the latest repo into your current project.
The benefit of doing this is that the code can be reused across every project without having to worry about broken development tress.
Documentation Source: https://cloud.google.com/python/docs/reference/storage/latest
Run the following
pip install google-cloud-storage
src = https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-python
Run the following and follow the prompts
gcloud auth application-default login
Source : https://cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.client.Client
project_id = '{YOUR PROJECT}'
gcs = GCSClient(project_id, credentials_path=None)
# List buckets to test client authorization
buckets = gcs.list_buckets()
print("Buckets:", buckets)
# creating a new bucket if it doesn't exist
bucket_name = "loc-scraper"
bucket = gcs.create_bucket(bucket_name=bucket_name)
print(bucket)