Adapts the grpc surface.


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


StatusCode Mirrors grpc_status_code in the gRPC Core.


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

Inverse map for STATUS_CODE_NAMES

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

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.

  • 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.

A gRPC client stub.

Return type:



Retrieves the status code from an exception