pythongoogle-cloud-platformgoogle-apigoogle-compute-enginegoogle-compute-api

GCP Compute Engine Python API proper way to create clients


What is the current "standard" way to create a gcp compute client in python? I have seen both:

import googleapiclient.discovery
service = googleapiclient.discovery.build(
        'container', 'v1', credentials=credentials)

body = {
    "autoCreateSubnetworks": False,
    "description": "",
    "mtu": 1460.0,
    "name": "test_network",
    "routingConfig": {
        "routingMode": "REGIONAL"
    }
}

network = compute.networks().insert(project=project_id, body=body, requestId=str(uuid.uuid4())).execute()

and:

from google.cloud import compute_v1        
compute = compute_v1.InstancesClient(credentials=credentials)

net = compute.Network()
net.auto_create_subnetworks = False
net.description = ""
net.mtu = 1460.0
net.name = "test_network"
net.routing_config = {
    "routingMode": "REGIONAL"
}

request = InsertNetworkRequest()
request.project = project_id
request.request_id = str(uuid.uuid4())
request.network_resource = net

network = compute.NetworksClient().insert(request=request)

Does Google plan on only supporting one somewhere down the road?


Solution

  • According to this repository google-api-python-client libraries where it's explained that it's supported for now, but there is no date yet for it to stop being updated.

    This library is considered complete and is in maintenance mode. This means that we will address critical bugs and security issues but will not add any new features.

    It's recommended to use the repository google-cloud-python which has 3 development branches, GA (General Availability), Beta Support and Alpha Support.