Library for communication with microservices developed by phonexia using grpc application interface.
Project description
Phonexia microservice communication via grpc library
This library contains defined interfaces for all microservices developed by Phonexia.
To use this library you will first need a running instance of any Phonexia microservice. If you don't yet have any running instance, don't hesitate to contact our sales department.
On this page, you may find a gRPC API reference for all microservices.
Example
Examples require microservice running on local machine at port 8080.
Health check
You can invoke health check
method of any microservice like this:
import grpc
from phonexia.grpc.common.health_check_pb2 import HealthCheckRequest
from phonexia.grpc.common.health_check_pb2_grpc import HealthStub
def health_check(stub: HealthStub):
"""Create request and call the service.
Invoke Info method of the health stub.
Args:
stub (LicensingStub): Created stub for communication with service.
"""
request = HealthCheckRequest()
response = stub.Check(request)
print(response)
def main():
"""Create a gRPC channel and connect to the service."""
with grpc.insecure_channel(target="localhost:8080") as channel:
"""Create channel to the service.
The target parameter is the service address and port.
insecure channel is used for connection without TLS.
To use SSl/TLS see the grpc_secure_channel function.
"""
stub = HealthStub(channel)
health_check(stub)
if __name__ == "__main__":
main()
If the microservice is running, it should return: status: SERVING
.
Check license
Each microservice has licensed model which is required to run the service. You can fetch information about licensed models like this:
import grpc
from phonexia.grpc.common.licensing_pb2 import LicensingInfoRequest
from phonexia.grpc.common.licensing_pb2_grpc import LicensingStub
def licensing_check(stub: LicensingStub):
"""Create request and call the service.
Invoke Info method of the Licensing stub.
Args:
stub (LicensingStub): Created stub for communication with service.
"""
request = LicensingInfoRequest()
response = stub.Info(request)
print(
f"The license for technology '{response.technology_name}' with model"
f" '{response.model_info.name}:{response.model_info.version}'"
f" {'is' if response.is_valid else 'was'} valid until {response.valid_until}."
)
def main():
"""Create a gRPC channel and connect to the service."""
with grpc.insecure_channel(target="localhost:8080") as channel:
"""Create channel to the service.
The target parameter is the service address and port.
insecure channel is used for connection without TLS.
To use SSl/TLS see the grpc_secure_channel function.
"""
stub = LicensingStub(channel=channel)
licensing_check(stub)
if __name__ == "__main__":
main()
Returned message should contain information about technology name, model name with version and time validity of license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file phonexia_grpc-1.1.0.tar.gz
.
File metadata
- Download URL: phonexia_grpc-1.1.0.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.8.18 Linux/5.14.0-362.13.1.el9_3.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42e9b91d1c01c0f691ca4b93e635fb60c32e62ad57bf6cdc5d081f01b3a3a3b9 |
|
MD5 | 3d04d094725ca62c9a2498a0d167789d |
|
BLAKE2b-256 | 5909e1929959772dd14b02db4bcb3cffdd3362e50011bc540ae76721e42964df |
File details
Details for the file phonexia_grpc-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: phonexia_grpc-1.1.0-py3-none-any.whl
- Upload date:
- Size: 25.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.8.18 Linux/5.14.0-362.13.1.el9_3.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04dab883284e64bb433d4a7eb823184d028cd0f3834db4a30c51db8d60747a0f |
|
MD5 | 985a9df5d826792982135e4eea535e20 |
|
BLAKE2b-256 | 7610fd8d398f030fb9f2e5f83e605f9f3bd8383f64ee53c7966ffcf2bee5eddd |