Skip to content
Google Cloud Client Library for Ruby
Ruby Python HTML C Shell Dockerfile
Branch: master
Clone or download
blowmage feat(bigquery): Add range support for Google Sheets
* Add External::SheetsSource#range
* Add External::SheetsSource#range=

pr: #4030
Latest commit 404700b Sep 18, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Update (#2889) Feb 7, 2019
.kokoro chore: run presubmit test sequentially (#3952) Aug 27, 2019
acceptance/data Support Object Localization (#2487) Sep 26, 2018
gcloud Release gcloud 0.23.4 (#3946) Aug 23, 2019
google-cloud-asset Release google-cloud-asset 0.3.2 (#3981) Sep 4, 2019
google-cloud-automl refactor(automl): Update documentation Aug 28, 2019
google-cloud-bigquery-data_transfer refactor(bigquery-data_transfer): Update documentation Aug 28, 2019
google-cloud-bigquery feat(bigquery): Add range support for Google Sheets Sep 18, 2019
google-cloud-bigtable Release google-cloud-bigtable 0.6.1 (#3986) Sep 5, 2019
google-cloud-container Release google-cloud-container 0.5.1 (#3875) Aug 23, 2019
google-cloud-container_analysis Release google-cloud-container_analysis 0.3.1 (#3983) Sep 4, 2019
google-cloud-core Release google-cloud-core 1.3.1 (#3877) Aug 23, 2019
google-cloud-dataproc refactor(dataproc): Update documentation Aug 28, 2019
google-cloud-datastore Release google-cloud-datastore 1.6.0 (#3906) Aug 23, 2019
google-cloud-debugger refactor(debugger): Update documentation Aug 28, 2019
google-cloud-dialogflow Release google-cloud-dialogflow 0.6.0 (#3908) Aug 23, 2019
google-cloud-dlp refactor(dlp): Update documentation Aug 28, 2019
google-cloud-dns feat(dns): Support overriding of service endpoint (#4012) Sep 10, 2019
google-cloud-env Release google-cloud-env 1.2.1 (#3911) Aug 23, 2019
google-cloud-error_reporting refactor(error_reporting): Update documentation Aug 28, 2019
google-cloud-firestore config(firestore) Update network configuration Sep 4, 2019
google-cloud-irm refactor(irm): Update documentation Aug 28, 2019
google-cloud-kms refactor(kms): Update documentation Aug 28, 2019
google-cloud-language Release google-cloud-language 0.33.1 (#3915) Aug 23, 2019
google-cloud-logging refactor(logging): Update documentation Aug 28, 2019
google-cloud-monitoring refactor(monitoring): Update documentation Aug 28, 2019
google-cloud-os_login Release google-cloud-os_login 0.3.1 (#3918) Aug 23, 2019
google-cloud-phishing_protection Release google-cloud-phishing_protection 0.2.1 (#3919) Aug 23, 2019
google-cloud-pubsub Release google-cloud-pubsub 0.39.2 (#4026) Sep 17, 2019
google-cloud-recaptcha_enterprise refactor(recaptcha_enterprise): Update documentation Aug 28, 2019
google-cloud-redis refactor(redis): Update documentation Aug 28, 2019
google-cloud-resource_manager feat(resource_manager): Support overriding of service endpoint Sep 10, 2019
google-cloud-scheduler refactor(scheduler): Update documentation Aug 28, 2019
google-cloud-security_center Release google-cloud-security_center 0.3.2 (#3984) Sep 4, 2019
google-cloud-spanner Release google-cloud-spanner 1.10.1 (#3987) Sep 4, 2019
google-cloud-speech feat(speech): Add Speaker Diarization Sep 9, 2019
google-cloud-storage Release google-cloud-storage 1.21.0 (#3798) Aug 16, 2019
google-cloud-talent refactor(talent): Remove new resource classes Aug 28, 2019
google-cloud-tasks Release google-cloud-tasks 1.1.2 (#3985) Sep 4, 2019
google-cloud-text_to_speech Release google-cloud-text_to_speech 0.4.1 (#3930) Aug 23, 2019
google-cloud-trace refactor(trace): Update documentation Aug 28, 2019
google-cloud-translate feat(translate): Support overriding of service endpoint Sep 18, 2019
google-cloud-video_intelligence Release google-cloud-video_intelligence 1.4.0 (#3782) Aug 13, 2019
google-cloud-vision refactor(vision): Update documentation Aug 28, 2019
google-cloud-webrisk refactor(webrisk): Update documentation Aug 28, 2019
google-cloud Release google-cloud 0.61.0 (#3947) Aug 23, 2019
grafeas-client feat(grafeas): Update VERSION location and constant Sep 9, 2019
integration docs: fix bad links (#3783) Aug 14, 2019
rakelib chore: fix link tests (#3996) Sep 4, 2019
stackdriver-core Release stackdriver-core 1.3.4 (#3936) Aug 23, 2019
stackdriver Release stackdriver 0.15.5 (#3935) Aug 23, 2019
.gitignore Add __pycache__ to gitignore to prevent local synth from adding it (#… Jan 28, 2019 docs: fix bad links (#3783) Aug 14, 2019 Add Code of Conduct Aug 25, 2015
Gemfile Initial synth of AutoML library (#3529) Jun 27, 2019
LICENSE Update Apache Licence URL Dec 16, 2017 docs: fix bad links (#3783) Aug 14, 2019 docs: fix bad links (#3783) Aug 14, 2019
Rakefile chore: run presubmit test sequentially (#3952) Aug 27, 2019
Vagrantfile Switch vagrant to use ruby 2.3 Dec 28, 2015
renovate.json chore: configure renovate to ignore rubocop (#3813) Aug 20, 2019

Google Cloud Ruby Client

Idiomatic Ruby client for Google Cloud Platform services.

Coverage Status Gem Version

This client supports the following Google Cloud Platform services at a General Availability (GA) quality level:

This client supports the following Google Cloud Platform services at a Beta quality level:

This client supports the following Google Cloud Platform services at an Alpha quality level:

The support for each service is distributed as a separate gem. However, for your convenience, the google-cloud gem lets you install the entire collection.

If you need support for other Google APIs, check out the Google API Ruby Client library.

Quick Start

$ gem install google-cloud

The google-cloud gem shown above provides all of the individual service gems in the google-cloud-ruby project, making it easy to explore Google Cloud Platform. To avoid unnecessary dependencies, you can also install the service gems independently.


In general, the google-cloud-ruby library uses Service Account credentials to connect to Google Cloud services. When running on Compute Engine the credentials will be discovered automatically. When running on other environments, the Service Account credentials can be specified by providing the path to the JSON keyfile for the account (or the JSON itself) in environment variables. Additionally, Cloud SDK credentials can also be discovered automatically, but this is only recommended during development.

General instructions, environment variables, and configuration options are covered in the general Authentication guide for the google-cloud umbrella package. Specific instructions and environment variables for each individual service are linked from the README documents listed below for each service.

The preview examples below demonstrate how to provide the Project ID and Credentials JSON file path directly in code.

Cloud Asset API (Beta)

Quick Start

$ gem install google-cloud-asset

BigQuery (GA)

Quick Start

$ gem install google-cloud-bigquery


require "google/cloud/bigquery"

bigquery =
dataset = bigquery.create_dataset "my_dataset"

table = dataset.create_table "my_table" do |t| = "My Table"
  t.description = "A description of my table."
  t.schema do |s|
    s.string "first_name", mode: :required
    s.string "last_name", mode: :required
    s.integer "age", mode: :required

# Load data into the table from Google Cloud Storage
table.load "gs://my-bucket/file-name.csv"

# Run a query
data = dataset.query "SELECT first_name FROM my_table"

data.each do |row|
  puts row[:first_name]

BigQuery Data Transfer API (Beta)

Quick Start

$ gem install google-cloud-bigquery-data_transfer


require "google/cloud/bigquery/data_transfer"

data_transfer_service_client =
formatted_parent = Google::Cloud::Bigquery::DataTransfer::V1::DataTransferServiceClient.project_path(project_id)

# Iterate over all results.
data_transfer_service_client.list_data_sources(formatted_parent).each do |element|
  # Process element.

# Or iterate over results one page at a time.
data_transfer_service_client.list_data_sources(formatted_parent).each_page do |page|
  # Process each page at a time.
  page.each do |element|
    # Process element.

Cloud Bigtable (Beta)

Quick Start

$ gem install google-cloud-bigtable


require "google/cloud/bigtable"

bigtable =

table = bigtable.table("my-instance", "my-table")

entry = table.new_mutation_entry("user-1")
  timestamp: * 1000 # Time stamp in milli seconds.
).delete_cells("cf2", "field02")


Cloud Datastore (GA)

Follow the activation instructions to use the Google Cloud Datastore API with your project.

Quick Start

$ gem install google-cloud-datastore


require "google/cloud/datastore"

datastore =
  project_id: "my-todo-project",
  credentials: "/path/to/keyfile.json"

# Create a new task to demo datastore
task = datastore.entity "Task", "sampleTask" do |t|
  t["type"] = "Personal"
  t["done"] = false
  t["priority"] = 4
  t["description"] = "Learn Cloud Datastore"

# Save the new task task

# Run a query for all completed tasks
query = datastore.query("Task").
  where("done", "=", false)
tasks = query

Stackdriver Debugger (Beta)

Quick Start

$ gem install google-cloud-debugger


require "google/cloud/debugger"

debugger =

Cloud DNS (Alpha)

Quick Start

$ gem install google-cloud-dns


require "google/cloud/dns"

dns =

# Retrieve a zone
zone = "example-com"

# Update records in the zone
change = zone.update do |tx|
  tx.add     "www", "A",  86400, ""
  tx.remove  "", "TXT"
  tx.replace "", "MX", 86400, ["10",
  tx.modify "", "CNAME" do |r|
    r.ttl = 86400 # only change the TTL

Container Analysis (Alpha)

Quick Start

$ gem install google-cloud-container_analysis


require "google/cloud/container_analysis"

container_analysis_client =
grafeas_client = container_analysis_client.grafeas_client
parent = Grafeas::V1::GrafeasClient.project_path "my-project"
results = grafeas_client.list_occurrences(parent).each do |occurrence|
  # do something with occurrence

Container Engine (Alpha)

Quick Start

$ gem install google-cloud-container


require "google/cloud/container"

cluster_manager_client =
project_id_2 = project_id
zone = "us-central1-a"
response = cluster_manager_client.list_clusters(project_id_2, zone)

Cloud Dataproc (Alpha)

Quick Start

$ gem install google-cloud-dataproc


require "google/cloud/dataproc"

cluster_controller_client =
project_id_2 = project_id
region = "global"

# Iterate over all results.
cluster_controller_client.list_clusters(project_id_2, region).each do |element|
  # Process element.

# Or iterate over results one page at a time.
cluster_controller_client.list_clusters(project_id_2, region).each_page do |page|
  # Process each page at a time.
  page.each do |element|
    # Process element.

Data Loss Prevention (Alpha)

Quick Start

$ gem install google-cloud-dlp


require "google/cloud/dlp"

dlp_service_client =
min_likelihood = :POSSIBLE
inspect_config = { min_likelihood: min_likelihood }
type = "text/plain"
value = "my phone number is 215-512-1212"
items_element = { type: type, value: value }
items = [items_element]
response = dlp_service_client.inspect_content(inspect_config, items)

Dialogflow API (Alpha)

Quick Start

$ gem install google-cloud-dialogflow

Stackdriver Error Reporting (Beta)

Quick Start

$ gem install google-cloud-error_reporting


require "google/cloud/error_reporting"

# Report an exception
  fail "Boom!"
rescue => exception exception

Cloud Firestore (GA)

Quick Start

$ gem install google-cloud-firestore


require "google/cloud/firestore"

firestore =
  project_id: "my-project",
  credentials: "/path/to/keyfile.json"

city = firestore.col("cities").doc("SF")
city.set({ name: "San Francisco",
           state: "CA",
           country: "USA",
           capital: false,
           population: 860000 })

firestore.transaction do |tx|
  new_population = tx.get(city).data[:population] + 1
  tx.update(city, { population: new_population })

Cloud Key Management Service (GA)

Quick Start

$ gem install google-cloud-kms


require "google/cloud/kms"

# Create a client for a project and given credentials
kms = credentials: "/path/to/keyfile.json"

# Where to create key rings
key_ring_parent = kms.class.location_path "my-project", "us-central1"

# Create a new key ring
key_ring = kms.create_key_ring key_ring_parent, "my-ring", {}
puts "Created at #{ key_ring.create_time.seconds}"

# Iterate over created key rings
kms.list_key_rings(key_ring_parent).each do |key_ring|
  puts "Found ring called #{}"

Stackdriver Logging (GA)

Quick Start

$ gem install google-cloud-logging


require "google/cloud/logging"

logging =

# List all log entries
logging.entries.each do |e|
  puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"

# List only entries from a single log
entries = logging.entries filter: "log:syslog"

# Write a log entry
entry = logging.entry
entry.payload = "Job started."
entry.log_name = "my_app_log"
entry.resource.type = "gae_app"
entry.resource.labels[:module_id] = "1"
entry.resource.labels[:version_id] = "20150925t173233"

logging.write_entries entry

Cloud Natural Language API (Alpha)

Quick Start

$ gem install google-cloud-language


require "google/cloud/language"

language =
  project_id: "my-todo-project",
  credentials: "/path/to/keyfile.json"

content = "Star Wars is a great movie. The Death Star is fearsome."
document = language.document content
annotation = document.annotate

annotation.entities.count #=> 3
annotation.sentiment.score #=> 0.10000000149011612
annotation.sentiment.magnitude #=> 1.100000023841858
annotation.sentences.count #=> 2
annotation.tokens.count #=> 13

Cloud OS Login (Alpha)

Quick Start

$ gem install google-cloud-os_login

Phishing Protection (Alpha)

Quick Start

$ gem install google-cloud-phishing_protection

Cloud Pub/Sub (Beta)

Quick Start

$ gem install google-cloud-pubsub


require "google/cloud/pubsub"

pubsub =
  project_id: "my-todo-project",
  credentials: "/path/to/keyfile.json"

# Retrieve a topic
topic = pubsub.topic "my-topic"

# Publish a new message
msg = topic.publish "new-message"

# Retrieve a subscription
sub = pubsub.subscription "my-topic-sub"

# Create a subscriber to listen for available messages
subscriber = sub.listen do |received_message|
  # process message

# Start background threads that will call the block passed to listen.

# Shut down the subscriber when ready to stop receiving messages.

Recaptcha Enterprise (Alpha)

Quick Start

$ gem install google-cloud-recaptcha_enterprise

Cloud Redis API (Alpha)

Quick Start

$ gem install google-cloud-redis

Cloud Resource Manager (Alpha)

Quick Start

$ gem install google-cloud-resource_manager


require "google/cloud/resource_manager"

resource_manager =

# List all projects
resource_manager.projects.each do |project|
  puts projects.project_id

# Label a project as production
project = resource_manager.project "tokyo-rain-123"
project.update do |p|
  p.labels["env"] = "production"

# List only projects with the "production" label
projects = resource_manager.projects filter: "labels.env:production"

Stackdriver Trace (Beta)

Quick Start

$ gem install google-cloud-trace


require "google/cloud/trace"

trace =

result_set = trace.list_traces - 3600,
result_set.each do |trace_record|
  puts "Retrieved trace ID: #{trace_record.trace_id}"

Cloud Spanner API (GA)

Quick Start

$ gem install google-cloud-spanner


require "google/cloud/spanner"

spanner =

db = spanner.client "my-instance", "my-database"

db.transaction do |tx|
  results = tx.execute "SELECT * FROM users"

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"

Cloud Speech API (Alpha)

Quick Start

$ gem install google-cloud-speech


require "google/cloud/speech"

speech =

audio = "path/to/audio.raw",
                     encoding: :raw, sample_rate: 16000
results = audio.recognize

result = results.first
result.transcript #=> "how old is the Brooklyn Bridge"
result.confidence #=> 0.9826789498329163

Cloud Scheduler (Alpha)

Quick Start

In order to use this library, you first need to go through the following steps:

  1. Select or create a Cloud Platform project.
  2. Enable billing for your project.
  3. Enable the Cloud Scheduler API.
  4. Setup Authentication.


$ gem install google-cloud-scheduler

Next Steps

Enabling Logging

To enable logging for this library, set the logger for the underlying gRPC library. The logger that you set may be a Ruby stdlib Logger as shown below, or a Google::Cloud::Logging::Logger that will write logs to Stackdriver Logging. See grpc/logconfig.rb and the gRPC spec_helper.rb for additional information.

Configuring a Ruby stdlib logger:

require "logger"

module MyLogger
  LOGGER = $stderr, level: Logger::WARN
  def logger

# Define a gRPC module-level logger method before grpc/logconfig.rb loads.
module GRPC
  extend MyLogger

Cloud Security Center API (Alpha)

Quick Start

$ gem install google-cloud-security_center

Cloud Storage (GA)

Quick Start

$ gem install google-cloud-storage


require "google/cloud/storage"

storage =
  project_id: "my-todo-project",
  credentials: "/path/to/keyfile.json"

bucket = storage.bucket "task-attachments"

file = bucket.file "path/to/my-file.ext"

# Download the file to the local file system "/tasks/attachments/#{}"

# Copy the file to a backup bucket
backup = storage.bucket "task-attachment-backups"
file.copy backup,

Cloud Talent Solutions API (Alpha)

Quick Start

$ gem install google-cloud-talent


 require "google/cloud/talent"

 require "google/cloud/talent"
 job_service_client = :v4beta1)
 formatted_parent = job_service_client.project_path("[PROJECT]")

 # TODO: Initialize `filter`:
 filter = ''
 # Iterate over all results.
 job_service_client.list_jobs(formatted_parent, filter).each do |element|
   # Process element.

 # Or iterate over results one page at a time.
 job_service_client.list_jobs(formatted_parent, filter).each_page do |page|
   # Process each page at a time.
   page.each do |element|
     # Process element.

Cloud Tasks API (Alpha)

Quick Start

$ gem install google-cloud-tasks


 require "google/cloud/tasks/v2beta2"

 cloud_tasks_client =
 formatted_parent = Google::Cloud::Tasks::V2beta2::CloudTasksClient.location_path("[PROJECT]", "[LOCATION]")

 # Iterate over all results.
 cloud_tasks_client.list_queues(formatted_parent).each do |element|
   # Process element.

 # Or iterate over results one page at a time.
 cloud_tasks_client.list_queues(formatted_parent).each_page do |page|
   # Process each page at a time.
   page.each do |element|
     # Process element.

Cloud Text To Speech API (Alpha)

Quick Start

$ gem install google-cloud-text_to_speech


require "google/cloud/text_to_speech"

text_to_speech_client =
text = "test"
input = { text: text }
language_code = "en-US"
voice = { language_code: language_code }
audio_encoding = :MP3
audio_config = { audio_encoding: audio_encoding }
response = text_to_speech_client.synthesize_speech(input, voice, audio_config)
File.write("example.mp3", response.audio_content, mode: "wb")

Cloud Translation API (GA)

Quick Start

$ gem install google-cloud-translate


require "google/cloud/translate"

translate =

translation = translate.translate "Hello world!", to: "la"

puts translation #=> Salve mundi!

translation.from #=> "en"
translation.origin #=> "Hello world!" #=> "la"
translation.text #=> "Salve mundi!"

Cloud Vision API (Alpha)

Quick Start

$ gem install google-cloud-vision


require "google/cloud/vision"

image_annotator_client =
gcs_image_uri = "gs://gapic-toolkit/President_Barack_Obama.jpg"
source = { gcs_image_uri: gcs_image_uri }
image = { source: source }
features_element = { type: type }
features = [features_element]
requests_element = { image: image, features: features }
requests = [requests_element]
response = image_annotator_client.batch_annotate_images(requests)

Stackdriver Monitoring API (Beta)

Quick Start

$ gem install google-cloud-monitoring


 require "google/cloud/monitoring/v3"

 MetricServiceClient = Google::Cloud::Monitoring::V3::MetricServiceClient

 metric_service_client =
 formatted_name = MetricServiceClient.project_path(project_id)

 # Iterate over all results.
 metric_service_client.list_monitored_resource_descriptors(formatted_name).each do |element|
   # Process element.

 # Or iterate over results one page at a time.
 metric_service_client.list_monitored_resource_descriptors(formatted_name).each_page do |page|
   # Process each page at a time.
   page.each do |element|
     # Process element.

Cloud Video Intelligence API (GA)

Quick Start

$ gem install google-cloud-video_intelligence


 require "google/cloud/video_intelligence/v1beta2"

 video_intelligence_service_client =
 input_uri = "gs://cloud-ml-sandbox/video/chicago.mp4"
 features_element = :LABEL_DETECTION
 features = [features_element]

 # Register a callback during the method call.
 operation = video_intelligence_service_client.annotate_video(input_uri: input_uri, features: features) do |op|
   raise op.results.message if op.error?
   op_results = op.results
   # Process the results.

   metadata = op.metadata
   # Process the metadata.

 # Or use the return value to register a callback.
 operation.on_done do |op|
   raise op.results.message if op.error?
   op_results = op.results
   # Process the results.

   metadata = op.metadata
   # Process the metadata.

 # Manually reload the operation.

 # Or block until the operation completes, triggering callbacks on
 # completion.

Supported Ruby Versions

These libraries are currently supported on Ruby 2.3+.

Google provides official support for Ruby versions that are actively supported by Ruby Core—that is, Ruby versions that are either in normal maintenance or in security maintenance, and not end of life. Currently, this means Ruby 2.3 and later. Older versions of Ruby may still work, but are unsupported and not recommended. See for details about the Ruby support schedule.


This library follows Semantic Versioning.

Please note it is currently under active development. Any release versioned 0.x.y is subject to backwards incompatible changes at any time.

GA: Libraries defined at the GA (general availability) quality level are stable. The code surface will not change in backwards-incompatible ways unless absolutely necessary (e.g. because of critical security issues) or with an extensive deprecation period. Issues and requests against GA libraries are addressed with the highest priority.

Please note that the auto-generated portions of the GA libraries (the ones in modules such as v1 or v2) are considered to be of Beta quality, even if the libraries that wrap them are GA.

Beta: Libraries defined at a Beta quality level are expected to be mostly stable and we're working towards their release candidate. We will address issues and requests with a higher priority.

Alpha: Libraries defined at an Alpha quality level are still a work-in-progress and are more likely to get backwards-incompatible updates.


Contributions to this library are always welcome and highly encouraged.

See CONTRIBUTING for more information on how to get started.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See Code of Conduct for more information.


This library is licensed under Apache 2.0. Full license text is available in LICENSE.


Please report bugs at the project on Github. Don't hesitate to ask questions about the client or APIs on StackOverflow.

You can’t perform that action at this time.