Package: pip-services4-components
Portable Component Model for PythonThis module is a part of thePip.Servicespolyglot microservices toolkit.It defines a portable component model interfaces and provides utility classes to handle component lifecycle.The module contains the following packages:Build- basic factories for constructing objectsConfig- configuration patternRefer- locator inversion of control (IoC) patternRun- component life-cycle management patternsQuick links:LoggingConfigurationAPI ReferenceChange LogGet HelpContributeUseInstall the Python package aspipinstallpip_services4_componentsThen you are ready to start using the Pip.Services patterns to augment your backend code.For instance, here is how you can implement a component, that receives configuration, get assigned references,
can be opened and closed using the patterns from this module.frompip_services4_commons.configimportIConfigurable,ConfigParamsfrompip_services4_commons.referimportIReferenceable,IReferences,Descriptorfrompip_services4_commons.runimportIOpenableclassMyComponentA(IConfigurable,IReferenceable,IOpenable):_param1='ABC'_param2=123_another_component:MyComponentB_opened=Truedefconfigure(self,config):self._param1=ConfigParams.get_as_string_with_default("param1",self._param1)self._param2=config.get_as_integer_with_default("param2",self._param2)defset_references(self,references):self._another_component=references.get_one_required(Descriptor("myservice","mycomponent-b","*","*","1.0"))defis_opened(self):returnself._openeddefopen(self,context):self._opened=Trueprint("MyComponentA has been opened.")defclose(self,context):self._opened=Trueprint("MyComponentA has been closed.")Then here is how the component can be used in the codefrompip_services4_commons.configimportIConfigurable,ConfigParamsfrompip_services4_commons.referimportReferences,Descriptormy_component_A=MyComponentA()# Configure the componentmy_component_A.configure(ConfigParams.from_tuples('param1','XYZ','param2',987))# Set references to the componentmy_component_A.set_references(References.from_tuples(Descriptor("myservice","mycomponent-b","default","default","1.0"),my_component_B))# Open the componentmy_component_A.open(Context.from_trace_id("123"))print("MyComponentA has been opened.")If you need to create components using their locators (descriptors) implement
component factories similar to the example below.frompip_services4_commons.referimportDescriptorfrompip_services4_components.buildimportFactoryclassMyFactory(Factory):my_component_descriptor=Descriptor("myservice","mycomponent","default","*","1.0")def__init__(self):super(MyFactory,self).__init__()self.register_as_type(MyFactory.my_component_descriptor,MyFactory)# Using the factorymy_factory=MyFactory()my_component1=my_factory.create(Descriptor("myservice","mycomponent","default","myComponent1","1.0"))my_component2=my_factory.create(Descriptor("myservice","mycomponent","default","myComponent2","1.0"))...DevelopFor development you shall install the following prerequisites:Python 3.7+Visual Studio Code or another IDE of your choiceDockerInstall dependencies:pipinstall-rrequirements.txtRun automated tests:pythontest.pyGenerate API documentation:./docgen.ps1Before committing changes run dockerized build and test as:./build.ps1
./test.ps1
./clear.ps1ContactsThe initial implementation is done bySergey Seroukhov. Pip.Services team is looking for volunteers to
take ownership over Python implementation in the project.