You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repository contains python samples intended to use in day to day operational activities on google cloud platform.
3
4
Usecases for which the python scripts are written can be found [here](./usecases.md).
4
5
5
6
## Prerequisites
7
+
6
8
Below prerequisites must be fulfilled for the successful execution of code.
7
9
8
10
### Software Requirement
11
+
9
12
Resources in this repository are meant for use with Python 3.x (check the version using `python3 --version`) and pip3 (check the version using `pip3 --version`). If you don't have the compatible version, download it from official python repository.
[venv](https://docs.python.org/3/library/venv.html) is a tool that creates isolated Python environments. These isolated environments can have separate versions of Python packages, which allows you to isolate one project's dependencies from the dependencies of other projects.
16
20
17
21
**Linux**
18
-
```
19
-
cd your-project
20
-
python3 -m venv env
21
-
source env/bin/activate
22
-
pip install -r requirements.txt
23
22
24
-
* If you want to stop using the virtual environment and go back to your global Python, you can deactivate it:
25
-
deactivate
23
+
```bash
24
+
cd your-project
25
+
python3 -m venv env
26
+
source env/bin/activate
27
+
pip install -r requirements.txt
28
+
29
+
# If you want to stop using the virtual environment and go back to your global Python, you can deactivate it:
30
+
deactivate
26
31
```
27
32
28
33
**Note:** Follow the [google article](https://cloud.google.com/python/docs/setup) to setup your Python development environment.
29
34
30
35
## Quick Start
36
+
31
37
If you want to quickly run and test Python samples without installing python, the recommended approach is to use Cloud Shell.
32
38
33
39
Cloud Shell is a Compute Engine virtual machine. The service credentials associated with this virtual machine are automatic, so there is no need to set up or download a service account key.
34
40
35
41
Cloud shell terminal is preloaded with softwares and utilities such as Python, gcloud command-line tool, kubectl, and more. letting you get started with less setup.
36
-
-**Step-01:** Activate Cloud Shell at the top of the Google Cloud Console.
37
-
-**Step-02:** Clone this repository: `git clone https://github.com/anupam-sy/python-gcp-samples.git`
38
-
-**Step-03:** Setup the python virtual environment using [Bootstrap Virtual Environment](#bootstrap-virtual-environment).
42
+
43
+
-[x]**Step-01:** Activate Cloud Shell at the top of the Google Cloud Console.
44
+
-[x]**Step-02:** Clone this repository: `git clone https://github.com/anupam-sy/python-gcp-samples.git`
45
+
-[x]**Step-03:** Setup the python virtual environment using [Bootstrap Virtual Environment](#bootstrap-virtual-environment).
39
46
40
47
### Authentication and Authorization
48
+
41
49
This client library used in the python script supports authentication via Google Application Default Credentials, or by providing a JSON key file for a Service Account. Google Application Default Credentials (ADC) is the recommended way to authorize and authenticate clients.
42
50
43
51
## Accessing Cloud APIs
52
+
44
53
You can access Cloud APIs using client libraries available for many popular programming languages While you can use Google Cloud APIs directly by making raw requests to the server, client libraries provide simplifications that significantly reduce the amount of code you need to write.
45
54
46
-
1. Cloud Client Libraries are the recommended option for accessing Cloud APIs programmatically, where available. Cloud Client Libraries use the latest client library model.
1. Cloud Client Libraries are the recommended option for accessing Cloud APIs programmatically, where available. Cloud Client Libraries use the latest client library model.
2. A few Google Cloud APIs don't have Cloud Client Libraries available in all languages. If you want to use one of these APIs and there is no Cloud Client Library for your preferred language, you can still use the previous style of client library, called Google API Client Libraries.
50
-
[OLD - Not Recommended]https://github.com/googleapis/google-api-python-client
58
+
2. A few Google Cloud APIs don't have Cloud Client Libraries available in all languages. If you want to use one of these APIs and there is no Cloud Client Library for your preferred language, you can still use the previous style of client library, called Google API Client Libraries.
59
+
[OLD - Not Recommended]https://github.com/googleapis/google-api-python-client
51
60
52
61
**Note:** It is recommended to use Cloud Client Libraries for Python, where possible, for new code development due to the following reasons:
53
62
54
63
With Cloud Client Libraries for Python:
64
+
55
65
- There is a separate client library for each API, so you can choose which client libraries to download. Whereas, google-api-python-client is a single client library for all APIs. As a result, the total package size for google-api-python-client exceeds 50MB.
56
66
- There are stricter controls for breaking changes to the underlying APIs as each client library is focused on a specific API.
57
67
- There are more features in these Cloud Client Libraries as each library is focused on a specific API, and in some cases, the libraries are owned by team who specialized in that API.
0 commit comments