Create a new Datastore admin client

Create a new Datastore admin client.

Code sample

C#

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries. For more information, see the Datastore mode C# API reference documentation.

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

// Create client
DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create();

Go

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries. For more information, see the Datastore mode Go API reference documentation.

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

import (
	"context"
	"fmt"
	"io"

	admin "cloud.google.com/go/datastore/admin/apiv1"
)

// clientCreate creates a new Datastore admin client.
func clientCreate(w io.Writer) (*admin.DatastoreAdminClient, error) {
	ctx := context.Background()
	client, err := admin.NewDatastoreAdminClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("admin.NewDatastoreAdminClient: %w", err)
	}
	// Close client when done using it.
	// defer client.Close()
	fmt.Fprintf(w, "Admin client created\n")
	return client, nil
}

Python

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries. For more information, see the Datastore mode Python API reference documentation.

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

from google.cloud.datastore_admin_v1 import DatastoreAdminClient


def client_create():
    """Creates a new Datastore admin client."""
    client = DatastoreAdminClient()

    print("Admin client created\n")
    return client

Ruby

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries. For more information, see the Datastore mode Ruby API reference documentation.

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

# Import the client library
require "google/cloud/datastore/admin/v1"

# Instantiate a client
client = Google::Cloud::Datastore::Admin::V1::DatastoreAdmin::Client.new

What's next

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