1# Copyright 2017 Google LLC 
    2# 
    3# Licensed under the Apache License, Version 2.0 (the "License"); 
    4# you may not use this file except in compliance with the License. 
    5# You may obtain a copy of the License at 
    6# 
    7#     http://www.apache.org/licenses/LICENSE-2.0 
    8# 
    9# Unless required by applicable law or agreed to in writing, software 
    10# distributed under the License is distributed on an "AS IS" BASIS, 
    11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
    12# See the License for the specific language governing permissions and 
    13# limitations under the License. 
    14 
    15"""Helpers for providing client information. 
    16 
    17Client information is used to send information about the calling client, 
    18such as the library and Python version, to API services. 
    19""" 
    20 
    21from google.api_core import client_info 
    22 
    23 
    24METRICS_METADATA_KEY = "x-goog-api-client" 
    25 
    26 
    27class ClientInfo(client_info.ClientInfo): 
    28    """Client information used to generate a user-agent for API calls. 
    29 
    30    This user-agent information is sent along with API calls to allow the 
    31    receiving service to do analytics on which versions of Python and Google 
    32    libraries are being used. 
    33 
    34    Args: 
    35        python_version (str): The Python interpreter version, for example, 
    36            ``'3.9.6'``. 
    37        grpc_version (Optional[str]): The gRPC library version. 
    38        api_core_version (str): The google-api-core library version. 
    39        gapic_version (Optional[str]): The version of gapic-generated client 
    40            library, if the library was generated by gapic. 
    41        client_library_version (Optional[str]): The version of the client 
    42            library, generally used if the client library was not generated 
    43            by gapic or if additional functionality was built on top of 
    44            a gapic client library. 
    45        user_agent (Optional[str]): Prefix to the user agent header. This is 
    46            used to supply information such as application name or partner tool. 
    47            Recommended format: ``application-or-tool-ID/major.minor.version``. 
    48        rest_version (Optional[str]): A string with labeled versions of the 
    49            dependencies used for REST transport. 
    50        protobuf_runtime_version (Optional[str]): The protobuf runtime version. 
    51    """ 
    52 
    53    def to_grpc_metadata(self): 
    54        """Returns the gRPC metadata for this client info.""" 
    55        return (METRICS_METADATA_KEY, self.to_user_agent()) 
    56 
    57 
    58DEFAULT_CLIENT_INFO = ClientInfo()