Package: pip-client-data-python
Client library for sample data microserviceThis is a client library to the sample data microservice. This library shall be used
as a template to create clients to general purpose data microservices.Supported functionality:Null and Mock clients for testingHTTP clients: REST and CommandableGRPC clients: Plain and CommandableAWS Lambda clients: Plain and CommandableKey patterns implemented in this library:Zero-time onboarding:A new developer doesn't have to have a prior khowledge of the code
nor preinstalled and preconfigured development environment.
To get started with any component he/she just need to do 3 simple steps:Checkout the codeLaunch dependencies viadocker-compose.dev.ymlExecutenpm test.Automated build and test processes:Clear, build and test actions are dockerized and scripted.
The scripts shall be run before committing the code. And the same scripts shall be executed in automated
CI/CD pipelines. That approach allows to make identical build and test actions across the entire delivery
pipeline. And have a clear separation between developer and DevOps roles (developers are responsible
for individual components, their build, test and packaging. DevOps are responsible for running CI/CD pipelines, assembling and testing entire system from individual components).Multiple communication protocols:The library contains clients that allow to connect to the microservice several different ways, depending on the environment or client requirements. For instance: on-premises the microservice can be deployed as a docker container. Locally it can be called via GRPC interface and externally via REST. When the same microservice is deployed on AWS cloud as a Lambda function, it can be called using the LambdaClient. Moreover, several microservice can be packaged into a single process, essentially represending a monolith. In that scenario, then can be called using in-process calls using the DirectClient.Monitoring and Observability:All clients are instrumented to collect logs of called operations, metrics that collect number of calls, average call times and number of erors, and traces. Depending on the deployment configuration that information can be sent to different destinations: console, Promethous, DataDog service, ApplicationInsights, CloudWatch and others.Versioning:Data objects and clients are versioned from the beginning. When breaking changes are introduced into the microservice, it shall keep the old version of the interface for backward-compatibility and expose a new version of the interface simultaniously. Then client library will have a new set of objects and clients for the new version, while keeping the old one intact. That will provide a clear versioning and backward-compatibility for users of the microservice.Quick links:Communication Protocols:gRPC Version 1HTTP Version 1MicroserviceAPI ReferenceChange LogContractThe contract of the microservice is presented below.classEntityV1(IStringIdentifiable):def__init__(self,id:str=None,site_id:str=None,type:str=None,name:str=None,content:str=None):self.id=id# Entity IDself.type=type# ID of a work site (field installation)self.site_id=site_id# Entity type: Type2, Type1 or Type3self.name=name# Human readable nameself.content=content# String contentclassIEntitiesClientV1(ABC):defget_entities(self,correlation_id:Optional[str],filter_params:FilterParams,paging:PagingParams)->DataPage:raiseNotImplementedError("Method is not implemented")defget_entities_by_id(self,correlation_id:Optional[str],entity_id:str)->EntityV1:raiseNotImplementedError("Method is not implemented")defget_entity_by_name(self,correlation_id:Optional[str],entity_name:str)->EntityV1:raiseNotImplementedError("Method is not implemented")defcreate_entity(self,correlation_id:Optional[str],entity:EntityV1)->EntityV1:raiseNotImplementedError("Method is not implemented")defupdate_entity(self,correlation_id:Optional[str],entity:EntityV1)->EntityV1:raiseNotImplementedError("Method is not implemented")defdelete_entity_by_id(self,correlation_id:Optional[str],entity_id:str)->EntityV1:raiseNotImplementedError("Method is not implemented")GetGet the microservice source from GitHub:gitclonegit@github.com:pip-templates-services/pip-service-data-python.gitInstall the microservice dependencies:pipinstall-rrequirements.txtInstall the client library as a binary dependency:pipinstallpip-client-data-pythonUseInstall the client pip package aspipinstallinstallpip-client-data-pythonInside your code get the reference to the client SDKfrompip_services3_commons.configimportConfigParamsfrompip_services3_commons.dataimportFilterParams,PagingParamsfrompip_service_data_python.data.EntityTypeV1importEntityTypeV1frompip_service_data_python.data.EntityV1importEntityV1frompip_client_data_python.clients.version1importEntitiesCommandableHttpClientV1Instantiate the client# Create the client instanceclient=EntitiesCommandableHttpClientV1()Define client connection parameters# Client configurationhttp_config=ConfigParams.from_tuples("connection.protocol","http","connection.host","localhost","connection.port",8080)# Configure the clientclient.configure(http_config)Connect to the microservice# Connect to the microserviceclient.open(None)# Work with the microservice...Call the microservice using the client API# Define a entityentity=EntityV1(id='1',site_id='1',type=EntityTypeV1.Type1,name='00001',content='ABC')# Create the entityentity=self.client.create_entity(None,ENTITY1)# Do something with the returned entity...# Get a list of entitiespage=self.client.get_entities(None,FilterParams.from_tuples("name","TestEntity",),PagingParams(0,10))# Do something with the returned page...# E.g. entity = page['data'][0]DevelopFor development you shall install the following prerequisites:Python 3.6+Visual Studio Code or another IDE of your choiceDockerInstall dependencies:pipinstall-rrequirements.txtBefore running tests launch infrastructure services and required microservices:docker-compose-f./docker-compose.dev.ymlupRun automated tests:pytestGenerate GRPC protobuf stubs:./protogen.ps1Generate API documentation:./docgen.ps1Before committing changes run dockerized build and test as:./build.ps1
./test.ps1
./package.ps1
./run.ps1
./clear.ps1ContactsThis microservice was created and currently maintained bySergey SeroukhovandDanil Prisyzhniy.