-
Notifications
You must be signed in to change notification settings - Fork 1
Intro to GCP Setting up and Firestore
Steve has already a good description here for installing and configuring GCP SDK for first time or a detailed description from GCP can be viewed here
- So now that we have installed and configured GCP SDK we have all the necessary tools ready for us to interact with GCP applications like gcloud CLI, bq and gustil.
Some handy commands for new users:
-
check the gcloud version and update it if required
$gcloud -v $gcloud components update
-
To list accounts whose credentials are stored on the local system:
$gcloud auth list
-
To set the active account, run:
$ gcloud config set account `ACCOUNT` # Account=xyz@gmail.com
-
current config info
$gcloud config list
-
All configuration and other information from this one command I like the most:
$gcloud info
-
gcloud handy commands cheatsheet and other tools guide (important for switching between projects and tools/applications etc).
My personal preference is to create a virtual environment (VENV) for each python project as to keep the dependencies for each of them cleanly separate. It often becomes a headache when two different projects would want to use different versions of python itself or libraries/packages. I use conda for venv else they could be created without it using python as described in here.
In this case I started with python 2.7 and later in the time I get to know that string handling in python 2.7 is causing trouble in GCP SDK Firebase client library by treating them as blobs - So I had to switch to python 3.7.x.
A helpful comprehensively described resource for conda venvs is here
A short summary of steps for getting started is below:
-
Check the conda version installed by typing in terminal client:
$conda -V conda 4.8.3
-
Check for updates and upadate the packages if necessary by typing y to proceed.
$conda update conda
-
Create a separate venv for working with and activate it
$conda create -n yourenvname python=3.7 anaconda $source activate yourenvname
You have to activate your venv every time you start a new session explicitly by source activating your venv name.
-
For checking the packages already installed in your venv after source activating it type :
$conda list
-
Install your required packages in your new venv by using first command below or directly activating your venv and then doing normal installations:
$conda install -n yourenvname [package]
For installing required firestore client and others opt form:google-cloud-* libraries or whatever you need:
$source activate yourenvname $pip install firebase-admin # sudo if needed $pip install google-cloud-firestore $pip install google-cloud-storage
-
For deactivating a venv (no need of venv name):
$conda deactivate
-
Because I have already many venvs and I often have to check the full venvs list for activating one of them which can be done by typing in terminal:
$conda env list
-
Remove venv:
$conda remove -n yourenvname -all
Cloud Firestore is a NoSQL, document-oriented database. Unlike a SQL database, there are no tables or rows. Instead, you store data in documents, which are organized into collections.
Collections are like directories.
- collections
- nested subcollections