Typing Stubs for grpcio-health-checking
This package provides static type checking stubs for the `grpcio-health-checking` library, enabling tools like MyPy to validate usage of `grpc_health.v1` modules. It is part of the `typeshed` project, which supplies type hints for many popular Python packages. The current version is 1.0.0.20260408, with releases tied to updates of the underlying runtime library.
Warnings
- gotcha This package provides only type stubs and does not contain any runtime code. Its sole purpose is to provide type information for static analysis tools like MyPy.
- gotcha Do not attempt to import symbols directly from `types_grpcio_health_checking`. The stub package augments the original `grpcio-health-checking` library. All imports should be made from `grpc_health.v1` modules as if the stubs were not present.
- breaking Type stubs are tightly coupled to the API of the runtime library they type. If you upgrade `grpcio-health-checking` to a new major version, the corresponding `types-grpcio-health-checking` stubs might become outdated or incorrect, potentially leading to type errors or undetected runtime issues.
- gotcha The version numbering for `types-` packages from `typeshed` (e.g., `1.0.0.20260408`) indicates the upstream package version (1.0.0) and the date the stub was generated/updated (20260408). It does not necessarily match the exact versioning scheme of the runtime `grpcio-health-checking` package.
Install
-
pip install types-grpcio-health-checking -
pip install grpcio grpcio-health-checking mypy
Imports
- HealthServicer
from grpc_health.v1.health import HealthServicer
- HealthCheckRequest
from grpc_health.v1 import health_pb2
Quickstart
import grpc
from grpc_health.v1 import health_pb2
from grpc_health.v1.health import HealthServicer
# This example demonstrates using type hints provided by types-grpcio-health-checking.
# For this code to run, 'grpcio' and 'grpcio-health-checking' must also be installed.
# The 'types-' package primarily assists static analysis tools like MyPy.
class MyHealthServicer(HealthServicer):
"""
An example gRPC Health Servicer implementation. The type hints for
`request` and the return value are validated by type checkers (like mypy)
thanks to the 'types-grpcio-health-checking' package providing stubs
for 'grpcio-health-checking'.
"""
def Check(self,
request: health_pb2.HealthCheckRequest,
context: grpc.ServicerContext) -> health_pb2.HealthCheckResponse:
"""
Implements the Check method of the gRPC Health Service.
"""
print(f"Received health check for service: {request.service}")
# In a real application, you'd check actual service status here.
if request.service == "myservice":
return health_pb2.HealthCheckResponse(status=health_pb2.HealthCheckResponse.ServingStatus.SERVING)
return health_pb2.HealthCheckResponse(status=health_pb2.HealthCheckResponse.ServingStatus.NOT_SERVING)
def Watch(self,
request: health_pb2.HealthCheckRequest,
context: grpc.ServicerContext) -> health_pb2.HealthCheckResponse:
"""
Implements the Watch method (streaming). For simplicity,
this example just yields a single response.
"""
yield health_pb2.HealthCheckResponse(status=health_pb2.HealthCheckResponse.ServingStatus.SERVING)
# To verify type-checking with MyPy:
# 1. Ensure you have 'grpcio', 'grpcio-health-checking', 'types-grpcio-health-checking', and 'mypy' installed.
# 2. Save this code as 'health_types_example.py'.
# 3. Run: mypy health_types_example.py
# If 'types-grpcio-health-checking' were missing, mypy would report errors for `HealthServicer` and other type hints.