This page shows how to get started with the Cloud Client Libraries for the
Google Cloud Storage API. Client libraries make it easier to access
Google Cloud APIs from a supported language. Although 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.

Read more about the Cloud Client Libraries
and the older Google API Client Libraries in
[Client libraries explained](https://docs.cloud.google.com/apis/docs/client-libraries-explained).

## Install the client library

### C++

For more information about installing the C++ library,
see [Setting up a C++ development environment](https://docs.cloud.google.com/cpp/docs/setup).

### C#

If you are using Visual Studio 2017 or higher, open nuget package manager window and type the following:

<br />

```
Install-Package Google.Cloud.Storage.V1
```

If you are using .NET Core command-line interface tools to install your dependencies, run the following command:

```
dotnet add package Google.Cloud.Storage.V1
```

For more information, see [Setting Up a C# Development Environment](https://docs.cloud.google.com/dotnet/docs/setup).

### Go

```
go get cloud.google.com/go/storage
```

For more information, see [Setting Up a Go Development Environment](https://docs.cloud.google.com/go/docs/setup).

### Java

If you are using [Maven](https://maven.apache.org/), add
the following to your `pom.xml` file. For more information about
BOMs, see [The Google Cloud Platform Libraries BOM](https://cloud.google.com/java/docs/bom).

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>com.google.cloud</groupId>
          <artifactId>libraries-bom</artifactId>
          <version>26.90.0</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
      </dependencies>
    </dependencyManagement>

    <dependencies>
      <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-storage</artifactId>
      </dependency>
      <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-storage-control</artifactId>
      </dependency>
    </dependencies>

If you are using [Gradle](https://gradle.org/),
add the following to your dependencies:

    implementation platform('com.google.cloud:libraries-bom:26.90.0')

    implementation 'com.google.cloud:google-cloud-storage'

If you are using [sbt](https://www.scala-sbt.org/), add
the following to your dependencies:

    libraryDependencies += "com.google.cloud" % "google-cloud-storage" % "2.77.0"

If you're using Visual Studio Code or IntelliJ, you can add client libraries to your
project using the following IDE plugins:

- [Cloud Code for VS Code](https://docs.cloud.google.com/code/docs/vscode/client-libraries)
- [Cloud Code for IntelliJ](https://docs.cloud.google.com/code/docs/intellij/client-libraries)

The plugins provide additional functionality, such as key management for service accounts. Refer
to each plugin's documentation for details.

> [!NOTE]
> **Note:** Cloud Java client libraries do not currently support Android.

For more information, see [Setting Up a Java Development Environment](https://docs.cloud.google.com/java/docs/setup).

### Node.js

```
npm install @google-cloud/storage
```

For more information, see [Setting Up a Node.js Development Environment](https://docs.cloud.google.com/nodejs/docs/setup).

### PHP

```
composer require google/cloud-storage
```

For more information, see [Using PHP on Google Cloud](https://docs.cloud.google.com/php/docs).

### Python

```
pip install --upgrade google-cloud-storage
```

For more information, see [Setting Up a Python Development Environment](https://docs.cloud.google.com/python/docs/setup).

### Ruby

```
gem install google-cloud-storage
```

For more information, see [Setting Up a Ruby Development Environment](https://docs.cloud.google.com/ruby/docs/setup).

<br />

## Set up authentication

To authenticate calls to Google Cloud APIs, client libraries support [Application Default Credentials (ADC)](https://docs.cloud.google.com/docs/authentication/application-default-credentials); the libraries look for credentials in a set of defined locations and use those credentials to authenticate requests to the API. With ADC, you can make credentials available to your application in a variety of environments, such as local development or production, without needing to modify your application code.

For production environments, the way you set up ADC depends on the service
and context. For more information, see [Set up Application Default Credentials](https://docs.cloud.google.com/docs/authentication/provide-credentials-adc).

For a local development environment, you can set up ADC with the credentials
that are associated with your Google Account:

1.
   [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

   After installation,
   [initialize](https://docs.cloud.google.com/sdk/docs/initializing) the Google Cloud CLI by running the following command:

   ```bash
   gcloud init
   ```


   If you're using an external identity provider (IdP), you must first
   [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).
2.

   If you're using a local shell, then create local authentication credentials for your user
   account:

   ```bash
   gcloud auth application-default login
   ```

   You don't need to do this if you're using Cloud Shell.


   If an authentication error is returned, and you are using an external identity provider
   (IdP), confirm that you have
   [signed in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).


   A sign-in screen appears. After you sign in, your credentials are stored in the
   [local credential file used by ADC](https://docs.cloud.google.com/docs/authentication/application-default-credentials#personal).

## Use the client library


The following example shows how to use the client library.

### C++

    #include "google/cloud/storage/client.h"
    #include <iostream>
    #include <random>
    #include <string>
    #include <utility>
    #include <vector>
    void StorageQuickstart(std::string const& bucket_name) {
      // Create an aliases to make the code easier to read.
      namespace gcs = ::google::cloud::storage;

      // Create a client to communicate with Google Cloud Storage. This client
      // uses the default configuration for authentication and project id.
      auto client = gcs::Client();

      // Create a bucket
      google::cloud::StatusOr<gcs::BucketMetadata> metadata = client.CreateBucket(
          bucket_name, gcs::BucketMetadata().set_location("US").set_storage_class(
                           gcs::storage_class::Standard()));
      if (!metadata) throw std::move(metadata).status();

      std::cout << "Created bucket " << metadata->name() << "\n";
    }

### C#


    using Google.Apis.Storage.v1.Data;
    using https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Storage.V1/latest/Google.Cloud.Storage.V1.html;
    using System;

    public class CreateBucketSample
    {
        public Bucket CreateBucket(
            string projectId = "your-project-id",
            string bucketName = "your-unique-bucket-name")
        {
            var storage = https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Storage.V1/latest/Google.Cloud.Storage.V1.StorageClient.html.https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Storage.V1/latest/Google.Cloud.Storage.V1.StorageClient.html#Google_Cloud_Storage_V1_StorageClient_Create();
            var bucket = storage.CreateBucket(projectId, bucketName);
            Console.WriteLine($"Created {bucketName}.");
            return bucket;
        }
    }

### Go


    // Sample storage-quickstart creates a Google Cloud Storage bucket.
    package main

    import (
    	"context"
    	"fmt"
    	"log"
    	"time"

    	"cloud.google.com/go/storage"
    )

    func main() {
    	ctx := context.Background()

    	// Sets your Google Cloud Platform project ID.
    	projectID := "YOUR_PROJECT_ID"

    	// Creates a client.
    	client, err := storage.NewClient(ctx)
    	if err != nil {
    		log.Fatalf("Failed to create client: %v", err)
    	}
    	defer client.Close()

    	// Sets the name for the new bucket.
    	bucketName := "my-new-bucket"

    	// Creates a Bucket instance.
    	bucket := client.https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/storage/latest/index.html#cloud_google_com_go_storage_Client_Bucket(bucketName)

    	// Creates the new bucket.
    	ctx, cancel := context.WithTimeout(ctx, time.Second*10)
    	defer cancel()
    	if err := bucket.https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/storage/latest/index.html#cloud_google_com_go_storage_BucketHandle_Create(ctx, projectID, nil); err != nil {
    		log.Fatalf("Failed to create bucket: %v", err)
    	}

    	fmt.Printf("Bucket %v created.\n", bucketName)
    }

### Java

    // Imports the Google Cloud client library
    import com.google.cloud.storage.https://docs.cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.Bucket.html;
    import com.google.cloud.storage.https://docs.cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.BucketInfo.html;
    import com.google.cloud.storage.https://docs.cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.Storage.html;
    import com.google.cloud.storage.https://docs.cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.StorageOptions.html;

    public class QuickstartSample {
      public static void main(String... args) throws Exception {
        // Instantiates a client
        https://docs.cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.Storage.html storage = https://docs.cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.StorageOptions.html.getDefaultInstance().https://docs.cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.transfermanager.TransferManagerConfig.html#com_google_cloud_storage_transfermanager_TransferManagerConfig_getService__();

        // The name for the new bucket
        String bucketName = args[0]; // "my-new-bucket";

        // Creates the new bucket
        https://docs.cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.Bucket.html bucket = storage.https://docs.cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.Storage.html#com_google_cloud_storage_Storage_create_com_google_cloud_storage_BlobInfo_byte___com_google_cloud_storage_Storage_BlobTargetOption____(BucketInfo.of(bucketName));

        System.out.printf("Bucket %s created.%n", bucket.getName());
      }
    }

### Node.js

    // Imports the Google Cloud client library
    const {Storage} = require('https://docs.cloud.google.com/nodejs/docs/reference/storage/latest/overview.html');

    // For more information on ways to initialize Storage, please see
    // https://googleapis.dev/nodejs/storage/latest/Storage.html

    // Creates a client using Application Default Credentials
    const storage = new https://docs.cloud.google.com/nodejs/docs/reference/storage-control/latest/storage-control/protos.google.storage.v2.storage-class.html();

    // Creates a client from a Google service account key
    // const storage = new Storage({keyFilename: 'key.json'});

    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // The ID of your GCS bucket
    // const bucketName = 'your-unique-bucket-name';

    async function createBucket() {
      // Creates the new bucket
      await storage.createBucket(bucketName);
      console.log(`Bucket ${bucketName} created.`);
    }

    createBucket().catch(console.error);

### PHP

    # Includes the autoloader for libraries installed with composer
    require __DIR__ . '/vendor/autoload.php';

    # Imports the Google Cloud client library
    use Google\Cloud\Storage\StorageClient;

    # Your Google Cloud Platform project ID
    $projectId = 'YOUR_PROJECT_ID';

    # Instantiates a client
    $storage = new StorageClient([
        'projectId' => $projectId
    ]);

    # The name for the new bucket
    $bucketName = 'my-new-bucket';

    # Creates the new bucket
    $bucket = $storage->createBucket($bucketName);

    echo 'Bucket ' . $bucket->name() . ' created.';

### Python

    # Imports the Google Cloud client library
    from google.cloud import https://docs.cloud.google.com/python/docs/reference/storage/latest

    # Instantiates a client
    storage_client = https://docs.cloud.google.com/python/docs/reference/storage/latest.https://docs.cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.client.Client.html()

    # The name for the new bucket
    bucket_name = "my-new-bucket"

    # Creates the new bucket
    bucket = storage_client.https://docs.cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.client.Client.html#google_cloud_storage_client_Client_create_bucket(bucket_name)

    print(f"Bucket {bucket.name} created.")

### Ruby

    def quickstart bucket_name:
      # Imports the Google Cloud client library
      require "google/cloud/storage"

      # Instantiates a client
      storage = Google::Cloud::https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage-control/latest/Google-Cloud-Storage.html.https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage.html

      # The ID to give your GCS bucket
      # bucket_name = "your-unique-bucket-name"

      # Creates the new bucket
      bucket = storage.https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Project.html bucket_name

      puts "Bucket #{bucket.name} was created."
    end

<br />


> [!NOTE]
> **Note:** These samples create a bucket in the default [`US` multi-region](https://docs.cloud.google.com/storage/docs/locations) with a default storage class of [`Standard Storage`](https://docs.cloud.google.com/storage/docs/storage-classes#standard). To create a bucket outside these defaults, see [Create buckets](https://docs.cloud.google.com/storage/docs/creating-buckets).

## Authentication options

By default, the client libraries use Application Default Credentials (ADC) to authenticate. For details on setting up ADC for local development or production, see [Set up authentication](https://docs.cloud.google.com/storage/docs/reference/libraries#authentication).

If you want to authenticate dynamically or by using in-memory keys, pass a custom credentials object when you initialize the client. For example, you might load keys from a secure vault or configuration system. For a Python code example and details on this configuration, see [Authorize using service account credentials](https://docs.cloud.google.com/storage/docs/authentication#passing-credentials-in-code).

## Using the client library with Cloud Shell Editor

### Go


*** ** * ** ***

For step-by-step guidance on running a client library in Cloud Shell Editor:

1. Click **Guide me**.

2. You see a panel **Learn** . Click **Start** to follow the tutorial.

[Guide me](https://console.cloud.google.com/?walkthrough_id=storage--client-libs-quickstart-go)

<br />

### Java


*** ** * ** ***

For step-by-step guidance on running a client library in Cloud Shell Editor:

1. Click **Guide me**.

2. You see a panel **Learn** . Click **Start** to follow the tutorial.

[Guide me](https://console.cloud.google.com/?walkthrough_id=storage--client-libs-quickstart-java)

<br />

### Node.js


*** ** * ** ***

For step-by-step guidance on running a client library in Cloud Shell Editor:

1. Click **Guide me**.

2. You see a panel **Learn** . Click **Start** to follow the tutorial.

[Guide me](https://console.cloud.google.com/?walkthrough_id=storage--client-libs-quickstart-nodejs)

<br />

### Python


*** ** * ** ***

For step-by-step guidance on running a client library in Cloud Shell Editor:

1. Click **Guide me**.

2. You see a panel **Learn** . Click **Start** to follow the tutorial.

[Guide me](https://console.cloud.google.com/?walkthrough_id=storage--client-libs-quickstart-python)

<br />

## More examples

For more examples of using client libraries with Cloud Storage, see the
following guides:

- [Create buckets](https://docs.cloud.google.com/storage/docs/creating-buckets#client-libraries)
- [Upload objects from a filesystem](https://docs.cloud.google.com/storage/docs/uploading-objects#storage-upload-object-client-libraries)
- [Download objects](https://docs.cloud.google.com/storage/docs/downloading-objects#client-libraries-download-object)

<br />

## Additional resources

### C++

The following list contains links to more resources related to the
client library for C++:

- [API reference](https://docs.cloud.google.com/cpp/docs/reference/storage/latest)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/google-cloud-cpp/issues)
- [`google-cloud-storage` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-cloud-storage%5D%5Bc%2B%2B%5D)
- [Source code](https://github.com/googleapis/google-cloud-cpp)

### C#

The following list contains links to more resources related to the
client library for C#:

- [API reference](https://docs.cloud.google.com/dotnet/docs/reference)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/google-cloud-dotnet/issues)
- [`google-cloud-storage` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-cloud-storage%5D+%5Bc%23%5D)
- [Source code](https://github.com/googleapis/google-cloud-dotnet)

### Go

The following list contains links to more resources related to the
client library for Go:

- [API reference](https://godoc.org/cloud.google.com/go/storage)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/google-cloud-go/issues)
- [`google-cloud-storage` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-cloud-storage%5D+%5Bgo%5D)
- [Source code](https://github.com/googleapis/google-cloud-go)

### Java

The following list contains links to more resources related to the
client library for Java:

- [API reference](https://docs.cloud.google.com/java/docs/reference/google-cloud-storage/latest/overview)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/java-storage/issues)
- [`google-cloud-storage` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-cloud-storage%5D+%5Bjava%5D)
- [Source code](https://github.com/googleapis/java-storage)

### Node.js

The following list contains links to more resources related to the
client library for Node.js:

- [API reference](https://docs.cloud.google.com/nodejs/docs/reference/storage/latest)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/nodejs-storage/issues)
- [`google-cloud-storage` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-cloud-storage%5D+%5Bnode.js%5D)
- [Source code](https://github.com/googleapis/nodejs-storage)

### PHP

The following list contains links to more resources related to the
client library for PHP:

- [API reference](https://cloud.google.com/php/docs/reference/cloud-storage/latest)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/google-cloud-php/issues)
- [`google-cloud-storage` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-cloud-storage%5D+%5Bphp%5D)
- [Source code](https://github.com/googleapis/google-cloud-php)

### Python

The following list contains links to more resources related to the
client library for Python:

- [API reference](https://docs.cloud.google.com/python/docs/reference/storage/latest)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/python-storage/issues)
- [`google-cloud-storage` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-cloud-storage%5D+%5Bpython%5D)
- [Source code](https://github.com/googleapis/python-storage)

### Ruby

The following list contains links to more resources related to the
client library for Ruby:

- [API reference](https://googleapis.dev/ruby/google-cloud-storage/latest/Google/Cloud/Storage.html)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/google-cloud-ruby/issues)
- [`google-cloud-storage` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-cloud-storage%5D+%5Bruby%5D)
- [Source code](https://github.com/googleapis/google-cloud-ruby)

<br />