google.gax.grpc

Adapts the grpc surface.

Functions

create_stub(generated_create_stub[, ...]) Creates a gRPC client stub.
exc_to_code(exc) Retrieves the status code from an exception

Classes

StatusCode Mirrors grpc_status_code in the gRPC Core.

Exceptions

RpcError Raised by the gRPC library to indicate non-OK-status RPC termination.
API_ERRORS = (<class 'grpc.RpcError'>,)

gRPC exceptions that indicate that an RPC was aborted.

NAME_STATUS_CODES = {<StatusCode.DATA_LOSS: (15, 'data loss')>: 'DATA_LOSS', <StatusCode.DEADLINE_EXCEEDED: (4, 'deadline exceeded')>: 'DEADLINE_EXCEEDED', <StatusCode.OUT_OF_RANGE: (11, 'out of range')>: 'OUT_OF_RANGE', <StatusCode.FAILED_PRECONDITION: (9, 'failed precondition')>: 'FAILED_PRECONDITION', <StatusCode.CANCELLED: (1, 'cancelled')>: 'CANCELLED', <StatusCode.INVALID_ARGUMENT: (3, 'invalid argument')>: 'INVALID_ARGUMENT', <StatusCode.PERMISSION_DENIED: (7, 'permission denied')>: 'PERMISSION_DENIED', <StatusCode.UNIMPLEMENTED: (12, 'unimplemented')>: 'UNIMPLEMENTED', <StatusCode.UNKNOWN: (2, 'unknown')>: 'UNKNOWN', <StatusCode.RESOURCE_EXHAUSTED: (8, 'resource exhausted')>: 'RESOURCE_EXHAUSTED', <StatusCode.NOT_FOUND: (5, 'not found')>: 'NOT_FOUND', <StatusCode.ABORTED: (10, 'aborted')>: 'ABORTED', <StatusCode.UNAUTHENTICATED: (16, 'unauthenticated')>: 'UNAUTHENTICATED', <StatusCode.INTERNAL: (13, 'internal')>: 'INTERNAL', <StatusCode.UNAVAILABLE: (14, 'unavailable')>: 'UNAVAILABLE'}

Inverse map for STATUS_CODE_NAMES

STATUS_CODE_NAMES = {'DATA_LOSS': <StatusCode.DATA_LOSS: (15, 'data loss')>, 'DEADLINE_EXCEEDED': <StatusCode.DEADLINE_EXCEEDED: (4, 'deadline exceeded')>, 'OUT_OF_RANGE': <StatusCode.OUT_OF_RANGE: (11, 'out of range')>, 'CANCELLED': <StatusCode.CANCELLED: (1, 'cancelled')>, 'FAILED_PRECONDITION': <StatusCode.FAILED_PRECONDITION: (9, 'failed precondition')>, 'INVALID_ARGUMENT': <StatusCode.INVALID_ARGUMENT: (3, 'invalid argument')>, 'PERMISSION_DENIED': <StatusCode.PERMISSION_DENIED: (7, 'permission denied')>, 'UNIMPLEMENTED': <StatusCode.UNIMPLEMENTED: (12, 'unimplemented')>, 'UNKNOWN': <StatusCode.UNKNOWN: (2, 'unknown')>, 'RESOURCE_EXHAUSTED': <StatusCode.RESOURCE_EXHAUSTED: (8, 'resource exhausted')>, 'NOT_FOUND': <StatusCode.NOT_FOUND: (5, 'not found')>, 'UNAVAILABLE': <StatusCode.UNAVAILABLE: (14, 'unavailable')>, 'UNAUTHENTICATED': <StatusCode.UNAUTHENTICATED: (16, 'unauthenticated')>, 'INTERNAL': <StatusCode.INTERNAL: (13, 'internal')>, 'ABORTED': <StatusCode.ABORTED: (10, 'aborted')>}

Maps strings used in client config to gRPC status codes.

create_stub(generated_create_stub, channel=None, service_path=None, service_port=None, credentials=None, scopes=None, ssl_credentials=None)[source]

Creates a gRPC client stub.

Parameters:
  • generated_create_stub (Callable) – The generated gRPC method to create a stub.
  • channel (grpc.Channel) – A Channel object through which to make calls. If None, a secure channel is constructed. If specified, all remaining arguments are ignored.
  • service_path (str) – The domain name of the API remote host.
  • service_port (int) – The port on which to connect to the remote host.
  • credentials (google.auth.credentials.Credentials) – The authorization credentials to attach to requests. These credentials identify your application to the service.
  • scopes (Sequence [ str ]) – The OAuth scopes for this service. This parameter is ignored if a credentials is specified.
  • ssl_credentials (grpc.ChannelCredentials) – gRPC channel credentials used to create a secure gRPC channel. If not specified, SSL credentials will be created using default certificates.
Returns:

A gRPC client stub.

Return type:

grpc.Client

exc_to_code(exc)[source]

Retrieves the status code from an exception