Basic portable abstractions for Pip.Services in Python
Project description
Portable Abstractions and Patterns for Python
This module is a part of the Pip.Services polyglot microservices toolkit. It provides a set of basic patterns used in microservices or backend services. Also the module implemenets a reasonably thin abstraction layer over most fundamental functions across all languages supported by the toolkit to facilitate symmetric implementation.
The module contains the following packages:
- Commands - commanding and eventing patterns
- Config - configuration pattern
- Convert - portable value converters
- Data - data patterns
- Errors- application errors
- Random - random data generators
- Refer - locator inversion of control (IoC) pattern
- Reflect - portable reflection utilities
- Run - component life-cycle management patterns
- Validate - validation patterns
- Configuration Pattern
- Locator Pattern
- Component Lifecycle
- Components with Active Logic
- Data Patterns
- API Reference
- Change Log
- Get Help
- Contribute
Use
Install the Python package as
pip install pip_services3_commons
Then 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.
from pip_services3_commons.config import IConfigurable, ConfigParams
from pip_services3_commons.refer import IReferenceable, IReferences, Descriptor
from pip_services3_commons.run import IOpenable
class MyComponentA(IConfigurable, IReferenceable, IOpenable):
_param1 = 'ABC'
_param2 = 123
_another_component: MyComponentB
_opened = True
def configure(self, config):
self._param1 = ConfigParams.get_as_string_with_default("param1", self._param1)
self._param2 = config.get_as_integer_with_default("param2", self._param2)
def set_references(self, references):
self._another_component = references.get_one_required(
Descriptor("myservice", "mycomponent-b", "*", "*", "1.0")
)
def is_opened(self):
return self._opened
def open(self, correlation_id):
self._opened = True
print("MyComponentA has been opened.")
def close(self, correlation_id):
self._opened = True
print("MyComponentA has been closed.")
Then here is how the component can be used in the code
from pip_services3_commons.config import IConfigurable, ConfigParams
from pip_services3_commons.refer import References, Descriptor
my_component_A = MyComponentA()
# Configure the component
my_component_A.configure(ConfigParams.from_tuples(
'param1', 'XYZ',
'param2', 987
))
# Set references to the component
my_component_A.set_references(References.from_tuples(
Descriptor("myservice", "mycomponent-b", "default", "default", "1.0"), my_component_B
))
# Open the component
my_component_A.open("123")
print("MyComponentA has been opened.")
Develop
For development you shall install the following prerequisites:
- Python 3.7+
- Visual Studio Code or another IDE of your choice
- Docker
Install dependencies:
pip install -r requirements.txt
Run automated tests:
python test.py
Generate API documentation:
./docgen.ps1
Before committing changes run dockerized build and test as:
./build.ps1
./test.ps1
./clear.ps1
Contacts
The library is created and maintained by:
- Sergey Seroukhov
- Danil Prisiazhnyi
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
File details
Details for the file pip_services3_commons-3.3.10.tar.gz.
File metadata
- Download URL: pip_services3_commons-3.3.10.tar.gz
- Upload date:
- Size: 87.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.26.0 setuptools/57.4.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a940ce9d56acb4e1a685a1bda3c7215b6721c2a62689e04a2d922faf09594d55
|
|
| MD5 |
77451e5e9f3f9eb36ff30eb584d5eaa8
|
|
| BLAKE2b-256 |
c28e3bcd99e6ec222d44db66491e32035112e14456caa3623ad8a6ae8171dd90
|