Construct a client

Constructs a Dataproc client using application default credentials.

Code sample

Python

Before trying this sample, follow the Python setup instructions in the Dataproc Quickstart Using Client Libraries. For more information, see the Dataproc Python API reference documentation.

if global_region:
    region = "global"
    # Use the default gRPC global endpoints.
    dataproc_cluster_client = dataproc_v1.ClusterControllerClient()
    dataproc_job_client = dataproc_v1.JobControllerClient()
else:
    region = get_region_from_zone(zone)
    # Use a regional gRPC endpoint. See:
    # https://cloud.google.com/dataproc/docs/concepts/regional-endpoints
    client_transport = cluster_controller_grpc_transport.ClusterControllerGrpcTransport(
        address="{}-dataproc.googleapis.com:443".format(region)
    )
    job_transport = job_controller_grpc_transport.JobControllerGrpcTransport(
        address="{}-dataproc.googleapis.com:443".format(region)
    )
    dataproc_cluster_client = dataproc_v1.ClusterControllerClient(client_transport)
    dataproc_job_client = dataproc_v1.JobControllerClient(job_transport)

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser