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
API_ERRORS = (<class 'grpc.RpcError'>,)

gRPC exceptions that indicate that an RPC was aborted.

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

Inverse map for STATUS_CODE_NAMES

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

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