This page provides links to convenient ways to access the Google Health API.

## Google Health API client libraries

The Google Health API is built on HTTP and JSON, so any standard HTTP client can
send requests to it and parse the responses.

However, instead of creating HTTP requests and parsing responses manually, you
may want to use the Google APIs client libraries. The client libraries provide
better language integration, improved security, and support for making calls
that require user authorization.

### Dart

Get the latest [Google Health API client library for Dart](https://pub.dev/packages/googleapis). Read the
client library's [developer's guide](https://pub.dev/documentation/googleapis/latest/).

### Go

Get the latest [Google Health API client library for Go](https://github.com/google/google-api-go-client). Read the
client library's [developer's guide](https://github.com/google/google-api-go-client).

### Java

<br />


This page contains information about getting started with the Google Health API by using
the Google API Client Library for Java. For more information, see the following documentation:

- Browse the [Javadoc reference for the Google Health API](https://googleapis.dev/java/google-api-services-health/latest/).
- Read the [Developer's Guide for the Google API Client Library for Java](https://github.com/googleapis/google-api-java-client/).

## Add the client library to your project

Select your build environment (Maven or Gradle) from the following tabs:


Maven

Add the following to your `pom.xml` file:
<iframe src="https://developers.devsite.google/frame/health/libraries_8431647a7049a1008ede24579b60bfb20b5a8fc9539d4df6f8819577a7808e29.frame" class="framebox inherit-locale " allow="clipboard-write https://developers.devsite.google" allowfullscreen is-upgraded></iframe>

See [all versions available on the Maven Central Repository](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.google.apis%22%20AND%20a%3A%22google-api-services-health%22).
Gradle

Add the following to your `build.gradle` file:
<iframe src="https://developers.devsite.google/frame/health/libraries_6d7be5d7a4f949139a59732c326e711462bccb564a0a66f875e582a254787d14.frame" class="framebox inherit-locale " allow="clipboard-write https://developers.devsite.google" allowfullscreen is-upgraded></iframe>

See [all versions available on the Maven Central Repository](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.google.apis%22%20AND%20a%3A%22google-api-services-health%22).

### JavaScript

Read the client library's [developer's guide](https://developers.google.com/api-client-library/javascript/start/start-js).

### .NET


This page contains information about getting started with the Google Health API by using
the Google API Client Library for .NET. For more information, see the following documentation:

- Browse the [.NET reference documentation for the Google Health API](https://googleapis.dev/dotnet/Google.Apis/latest/api/Google.Apis.html).
- Read the [Developer's guide for the Google API Client Library for .NET](https://developers.google.com/api-client-library/dotnet/get_started).

## Downloading the library

Install the NuGet package:
[Google.Apis](https://www.nuget.org/packages/Google.Apis).

### Node.js

Get the latest [Google Health API client library for Node.js](https://github.com/google/google-api-nodejs-client/). Read the
client library's [developer's guide](https://github.com/google/google-api-nodejs-client/).

### Obj-C

Get the latest [Google Health API client library for Objective-C](https://github.com/google/google-api-objectivec-client-for-rest). Read the
client library's [developer's guide](https://github.com/google/google-api-objectivec-client-for-rest/wiki).

### PHP

Get the latest [Google Health API client library for PHP](https://github.com/google/google-api-php-client). Read the
client library's [developer's guide](https://developers.google.com/api-client-library/php).

### Python


This page contains information about getting started with the Google Health API by using
the Google API Client Library for Python (v1/v2). For more information, see the following documentation:

- Browse the [PyDoc reference for the Google Health API](https://googleapis.github.io/google-api-python-client/docs/dyn/health_v4.html).
- Read the [Developer's guide for the Google API Client Library for Python (v1/v2)](https://developers.google.com/api-client-library/python).

## System requirements

- Operating systems:
  - Linux
  - macOS X
  - Windows
- [The v1 client library requires Python 2.7 or higher. The v2 client library requires 3.7 or higher.](http://python.org/download/)

## Install the client library

You can either use a package manager or manually download and install the Python client library:

### Managed install

Use pip or setuptools to manage your installation. You might
need to run `sudo` first.

- [pip](http://pypi.python.org/pypi/pip) (preferred):

  ```
  pip install --upgrade google-api-python-client
  ```
- [Setuptools](http://pypi.python.org/pypi/setuptools):

  ```
  easy_install --upgrade google-api-python-client
  ```

### Manual install

1. [Download the latest client
   library for Python](https://pypi.python.org/pypi/google-api-python-client/).
2. Unpack the code.
3. Install:

   ```
   python setup.py install
   ```

### App Engine

Because the Python client libraries aren't installed in the
[App Engine Python runtime environment](https://cloud.google.com/appengine/docs/python/),
you must [copy them into your application](https://cloud.google.com/appengine/docs/python/tools/libraries27#vendoring) just like third-party libraries.

<br />

### Ruby


This page contains information about getting started with the Google Health API by using
the Google API Client Library for Ruby. For more information, see the following documentation:

- Read the [Get started guide for the Google API Client Library for Ruby](https://developers.google.com/api-client-library/ruby/start/get_started).

## Install the `google-api-client` gem


Depending on your system, you might need to prepend these commands with `sudo`.


If you haven't installed the Google API Client Library for Ruby before, install by using `RubyGems`:

```
gem install google-api-client
```

<br />


If you already have the gem installed, update to the latest version:

```
gem update -y google-api-client
```

<br />

## Get started with the Google API Client Library for Ruby


To learn how to make your first request, see the
[Get started guide](https://developers.google.com/api-client-library/ruby/start/get_started).

<br />

## Command-line tool

The Google Health CLI (`ghealth`) is an open-source command-line tool for the
Google Health API. It handles OAuth 2.0 authorization, pagination, and response
formatting so you can query and manage health data from a terminal, scripts, or
AI coding agents.

[View on GitHub](https://github.com/Google-Health-API/google-health-cli)

> [!NOTE]
> **Note:** Using `ghealth` requires [Go](https://go.dev/doc/install) 1.23 or later and a configured Google Cloud project. See [Set up Google Cloud and OAuth](https://developers.google.com/health/setup) before starting.

1. Clone the
   [Google Health CLI repository](https://github.com/Google-Health-API/google-health-cli)
   and build the binary:

       git clone https://github.com/Google-Health-API/google-health-cli.git
       cd google-health-cli
       go build -o ghealth .

2. Run the setup wizard to configure your Google Cloud project, OAuth 2.0
   client, and [scopes](https://developers.google.com/health/scopes):

       ghealth setup

3. Run `ghealth` commands to list [data types](https://developers.google.com/health/data-types) or retrieve
   data points:

   ### Daily steps

   Retrieve daily step totals:

       ghealth data steps daily-rollup --from 2026-03-22 --to 2026-03-29

   Output:

       {
         "dataPoints": [
           {"date": "2026-03-28", "countSum": "9037"},
           {"date": "2026-03-27", "countSum": "2408"},
           {"date": "2026-03-26", "countSum": "6474"}
         ]
       }

   ### Heart rate

   List recent heart rate readings:

       ghealth data heart-rate list --from today --limit 10

   Output:

       {
         "dataPoints": [
           {
             "time": "2026-03-29T16:33:07+01:00",
             "beatsPerMinute": "80",
             "source": "Google Pixel Watch 4 (41mm)"
           },
           {
             "time": "2026-03-29T16:33:04+01:00",
             "beatsPerMinute": "80",
             "source": "Google Pixel Watch 4 (41mm)"
           }
         ]
       }

   ### Data types

   Discover available data types:

       ghealth schema types

   Output:

       {
         "types": [
           {
             "category": "activity_and_fitness",
             "description": "Step count data (use daily-rollup for totals)",
             "id": "steps",
             "operations": [
               "list",
               "rollup",
               "daily-rollup",
               "reconcile"
             ],
             "rollupOnly": false,
             "writable": false
           },
           {
             "category": "activity_and_fitness",
             "description": "Heart rate in beats per minute",
             "id": "heart-rate",
             "operations": [
               "list",
               "rollup",
               "daily-rollup",
               "reconcile"
             ],
             "rollupOnly": false,
             "writable": false
           }
         ],
         "source": "live"
       }

## gRPC

The Google Health API also supports gRPC for high-performance data retrieval.
In addition to installing client libraries, using gRPC requires obtaining the
API's Protocol Buffers definitions and generating client-side stub code
before making requests.

[Try the gRPC Codelab](https://developers.google.com/health/codelabs/make-your-first-api-call-using-grpc)

> [!NOTE]
> **Note:** The following instructions and code snippet illustrate how to use gRPC on Python. This is only one platform's implementation; other platforms should use their recommended tooling and compilers for generating code from protocol buffers (for example, `swift-protobuf` or `protoc` on Swift).

1. **Install gRPC libraries:**
   - Use `pip install grpcio grpcio-tools google-auth google-auth-oauthlib
     googleapis-common-protos` to install dependencies.
2. **Generate client code:**
   - Obtain the Google Health API `.proto` definitions (for example, `data_points.proto`).
   - Run `python -m grpc_tools.protoc -I. --python_out=.
     --grpc_python_out=. path/to/your/data_points.proto` to generate stub code.
3. **Implement OAuth 2.0 and make gRPC requests:**
   - Use `google-auth-oauthlib` for authorization and the generated client stub to make gRPC requests, as shown in the following example.

    import google.auth
    from google.auth.transport.grpc import secure_authorized_channel
    from google.auth.transport.requests import Request
    from google.oauth2.credentials import Credentials
    from google_auth_oauthlib.flow import InstalledAppFlow
    import os
    import json
    import grpc

    # Generated gRPC code from data_points.proto
    # These imports depend on the output of grpc_tools
    try:
        import data_points_pb2
        import data_points_pb2_grpc
    except ImportError:
        print("Please generate gRPC code from data_points.proto")
        data_points_pb2 = None
        data_points_pb2_grpc = None

    # --- REPLACE WITH YOUR VALUES ---
    CLIENT_SECRETS_FILE = 'path/to/your/client_secret.json'
    SCOPES = ['https://www.googleapis.com/auth/googlehealth.activity_and_fitness.readonly']  # Add other scopes as needed
    TOKEN_FILE = 'token.json'
    GRPC_ENDPOINT = 'health.googleapis.com' # Google Health API gRPC endpoint

    def get_credentials():
        """Gets or creates OAuth 2.0 credentials."""
        creds = None
        # The file token.json stores the user's access and refresh tokens, and is
        # created automatically when the authorization flow completes for the first
        # time.
        if os.path.exists(TOKEN_FILE):
            with open(TOKEN_FILE, 'r') as token:
                creds = Credentials.from_authorized_user_info(json.load(token), SCOPES)
        # If there are no (valid) credentials available, let the user log in.
        if creds and creds.expired and creds.refresh_token:
            try:
                creds.refresh(Request())
            except Exception as e:
                creds = None  # Force re-auth if refresh fails
        if not creds or not creds.valid:
            flow = InstalledAppFlow.from_client_secrets_file(
                CLIENT_SECRETS_FILE, SCOPES
            )
            creds = flow.run_local_server(port=0)
            # Save the credentials for the next run
            with open(TOKEN_FILE, 'w') as token:
                token.write(creds.to_json())
        return creds

    def fetch_health_data_grpc(creds):
        """Fetches health data using gRPC."""
        if not data_points_pb2_grpc:
            return
        try:
            # Create an authenticated gRPC channel
            channel = secure_authorized_channel(creds, Request(), f'{GRPC_ENDPOINT}:443')
            # Create a stub for the DataPointsService
            stub = data_points_pb2_grpc.DataPointsServiceStub(channel)

            # Example: list steps data points for the authenticated user 'me'
            request = data_points_pb2.ListDataPointsRequest(parent='users/me/dataTypes/steps')
            response = stub.ListDataPoints(request)
            print('Health data via gRPC:', response)
        except grpc.RpcError as e:
            print(f'Error fetching data via gRPC: {e.code()} - {e.details()}')
        except Exception as e:
            print(f'An error occurred during gRPC call: {e}')

    if __name__ == '__main__':
        try:
            creds = get_credentials()
            print("Fetching data using gRPC...")
            fetch_health_data_grpc(creds)
        except Exception as e:
            print(f"An error occurred: {e}")

- **Import Libraries:**
  - `grpc`: The gRPC Python library.
  - `google.auth.transport.grpc`: For creating secure, authenticated channels.
  - `data_points_pb2`, `data_points_pb2_grpc`: Client code generated from `.proto` files.
- **Configuration:**
  - `CLIENT_SECRETS_FILE`: Path to your `client_secret.json` file.
  - `SCOPES`: The required permissions.
  - `TOKEN_FILE`: Path to store OAuth tokens.
  - `GRPC_ENDPOINT`: The hostname for the Google Health gRPC service.
- **`get_credentials()`:**
  - Loads client secrets from file, uses `InstalledAppFlow` from `google-auth-oauthlib` to manage authorization, attempts to load stored credentials, or initiates the OAuth 2.0 flow if needed.
- **`fetch_health_data_grpc()`:**
  - Creates a secure, authenticated gRPC channel using the user's credentials.
  - Initializes a `DataPointsServiceStub` with the channel.
  - Creates a `ListDataPointsRequest` to request steps data for `users/me`.
  - Calls the `ListDataPoints` RPC method and prints the response.
- **Error Handling:** The code includes basic `try...except` blocks for handling gRPC and other errors.

## Generate sample data

Google doesn't provide pre-populated sample or mock health data. To test your
integration, you must generate your own test data. Use any of the following
methods to generate sample data for your test users:

- **Wear a tracker:** Wear a Fitbit tracker, Pixel Watch, or other smartwatch compatible with the Google Health app and walk around to generate steps, heart rate, and workout data.
- **Enable mobile tracking:** Enable MobileTrack in the Google Health app and walk around with your mobile device.
- **Log data manually:** Manually enter health metrics (such as sleep, weight, water, or food intake) through the Google Health app.
- **Write data using the API:** Send write requests (such as `POST` or `PATCH`) directly to the REST API endpoints to programmatically populate data. For more details on creating and updating data points, see the [REST reference documentation](https://developers.google.com/health/reference/rest/v4/users.dataTypes.dataPoints).