Class Client (1.15.3)

Client(project=None,credentials=None,_http=None,_use_grpc=None,client_info=None,client_options=None,)

Client to bundle configuration needed for API requests.

Parameters

NameDescription
projectstr

the project which the client acts on behalf of. If not passed, falls back to the default inferred from the environment.

credentialsgoogle.auth.credentials.Credentials

(Optional) The OAuth2 Credentials to use for this client. If not passed (and if no_http object is passed), falls back to the default inferred from the environment.

_httprequests.Session

(Optional) HTTP object to make requests. Can be any object that definesrequest() with the same interface asrequests.Session.request. If not passed, an_http object is created that is bound to thecredentials for the current object. This parameter should be considered private, and could change in the future.

_use_grpcbool

(Optional) Explicitly specifies whether to use the gRPC transport or HTTP. If unset, falls back to theGOOGLE_CLOUD_DISABLE_GRPC environment variable This parameter should be considered private, and could change in the future.

client_infogoogle.api_core.client_info.ClientInfo orgoogle.api_core.gapic_v1.client_info.ClientInfo

The client info used to send a user-agent string along with API requests. IfNone, then default info will be used. Generally, you only need to set this if you're developing your own library or partner tool.

client_optionsgoogle.api_core.client_options.ClientOptions ordict

(Optional) Client options used to set user options on the client. API Endpoint should be set through client_options.

Properties

logging_api

metrics_api

sinks_api

Methods

get_default_handler

get_default_handler(**kw)

Return the default logging handler based on the local environment.

Parameter
NameDescription
kwdict

keyword args passed to handler constructor

Returns
TypeDescription
logging.HandlerThe default log handler based on the environment

list_entries

list_entries(projects=None,filter_=None,order_by=None,page_size=None,page_token=None)
Parameters
NameDescription
projectslist of strings

project IDs to include. If not passed, defaults to the project bound to the client.

filter_str

a filter expression. Seehttps://cloud.google.com/logging/docs/view/advanced_filters

order_bystr

One of :data:ASCENDING or :data:DESCENDING.

page_sizeint

Optional. The maximum number of entries in each page of results from this request. Non-positive values are ignored. Defaults to a sensible value set by the API.

page_tokenstr

Optional. If present, return the next batch of entries, using the value, which must correspond to thenextPageToken value returned in the previous response. Deprecated: use thepages property of the returned iterator instead of manually passing the token.

Returns
TypeDescription
google.api_core.page_iterator.IteratorIterator of_BaseEntry accessible to the current client.

list_metrics

list_metrics(page_size=None,page_token=None)

List metrics for the project associated with this client.

Seehttps://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics/list

Parameters
NameDescription
page_sizeint

Optional. The maximum number of metrics in each page of results from this request. Non-positive values are ignored. Defaults to a sensible value set by the API.

page_tokenstr

Optional. If present, return the next batch of metrics, using the value, which must correspond to thenextPageToken value returned in the previous response. Deprecated: use thepages property of the returned iterator instead of manually passing the token.

Returns
TypeDescription
google.api_core.page_iterator.IteratorIterator ofMetric accessible to the current client.

list_sinks

list_sinks(page_size=None,page_token=None)

List sinks for the project associated with this client.

Seehttps://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks/list

Parameters
NameDescription
page_sizeint

Optional. The maximum number of sinks in each page of results from this request. Non-positive values are ignored. Defaults to a sensible value set by the API.

page_tokenstr

Optional. If present, return the next batch of sinks, using the value, which must correspond to thenextPageToken value returned in the previous response. Deprecated: use thepages property of the returned iterator instead of manually passing the token.

Returns
TypeDescription
google.api_core.page_iterator.IteratorIterator ofSink accessible to the current client.

logger

logger(name)

Creates a logger bound to the current client.

Parameter
NameDescription
namestr

the name of the logger to be constructed.

Returns
TypeDescription
LoggerLogger created with the current client.

metric

metric(name,filter_=None,description="")

Creates a metric bound to the current client.

Parameters
NameDescription
namestr

the name of the metric to be constructed.

filter_str

the advanced logs filter expression defining the entries tracked by the metric. If not passed, the instance should already exist, to be refreshed viaMetric.reload.

descriptionstr

the description of the metric to be constructed. If not passed, the instance should already exist, to be refreshed viaMetric.reload.

Returns
TypeDescription
MetricMetric created with the current client.

setup_logging

setup_logging(log_level=20,excluded_loggers=("google.cloud","google.auth","google_auth_httplib2"),**kw)

Attach default Stackdriver logging handler to the root logger.

This method uses the default log handler, obtained byget_default_handler, and attaches it to the root Pythonlogger, so that a call such aslogging.warn, as well as all childloggers, will report to Stackdriver logging.

Parameters
NameDescription
kwdict

keyword args passed to handler constructor

log_levelint

(Optional) Python logging log level. Defaults to :const:logging.INFO.

excluded_loggerstuple

(Optional) The loggers to not attach the handler to. This will always include the loggers in the path of the logging client itself.

sink

sink(name,filter_=None,destination=None)

Creates a sink bound to the current client.

Parameters
NameDescription
namestr

the name of the sink to be constructed.

filter_str

(optional) the advanced logs filter expression defining the entries exported by the sink. If not passed, the instance should already exist, to be refreshed viaSink.reload.

destinationstr

destination URI for the entries exported by the sink. If not passed, the instance should already exist, to be refreshed viaSink.reload.

Returns
TypeDescription
SinkSink created with the current client.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-01-10 UTC.