Current collected state Current
Observed since 21 Oct, 09:08 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
agi-med-grpc-interceptors
Interceptors for grpc
Стандартные middlewares для grpc
@zhelvakov
import grpc
from concurrent import futures
from agi_med_grpc_interceptors import LoggingInterceptor, ExcHandlerInterceptor
server = grpc.server(
futures.ThreadPoolExecutor(max_workers=10),
interceptors=[LoggingInterceptor(), ExcHandlerInterceptor()],
)
#server
from agi_med_grpc_interceptors import BaseGrpcError, DefaultValue
from grpc import StatusCode
from .some_protos.Some_pb2_grpc import SomeServicer
from .Some_pb import GetSalaryResponse, GetSalaryRequest
class EmployerNotFound(BaseGrpcError[float]):
def __init__(self, message: str) -> None:
default_value = DefaultValue[float](value=0)
super().__init__(StatusCode.ALREADY_EXISTS, message, default_value)
class Some(SomeServicer):
def GetSalary(self, request: GetSalaryRequest) -> GetSalaryResponse:
if request.Username == "bob":
raise EmployerNotFound("Bob, go to home!")
return GetSalaryResponse(salary=10_000)
#client
from agi_med_grpc_interceptors import BaseGrpcError, ErrorDetails
from grpc import RpcError
from .Some_pb import GetSalaryResponse, GetSalaryRequest
from .Some_pb2_grpc import SomeStub
stub = SomeStub("0.0.0.0:5000")
try:
request = GetSalaryRequest(Username="bob")
response: GetSalaryResponse = stub.DoSomething(request)
except RpcError as ex:
error: ErrorDetails[float] | None = BaseGrpcError[float].extract_error(ex)
default_value: float | None = BaseGrpcError[float].extract_default_value_from_error(ex)
print(f"{error=}")
print(f"{default_value=}")
pip install black flake8-pyproject mypy
black .
flake8
mypy .
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
grpcioEnvironment{
"extras": "",
"marker": null,
"requires_python": ">=3.11",
"evaluation": "NOT_EVALUATED"
} | grpcio~=1.68.1 | runtime |
grpcio-toolsEnvironment{
"extras": "",
"marker": null,
"requires_python": ">=3.11",
"evaluation": "NOT_EVALUATED"
} | grpcio-tools~=1.68.1 | runtime |
loguruEnvironment{
"extras": "",
"marker": null,
"requires_python": ">=3.11",
"evaluation": "NOT_EVALUATED"
} | loguru~=0.7.2 | runtime |
pydanticEnvironment{
"extras": "",
"marker": null,
"requires_python": ">=3.11",
"evaluation": "NOT_EVALUATED"
} | pydantic~=2.9.2 | runtime |
bdist_wheel · 8.78 KB · Python py3
sdist · 6.94 KB · Python source
Observed since 21 Oct, 09:08 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:6a2b70e90af225498a9331f36e34fe0b34cd526c2ab2f47ee7c7b0ab473c8677