Skip to main content

Pip.Services Logo
Portable Component Model for Python

This module is a part of the Pip.Services polyglot 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 objects
  • Config - configuration pattern
  • Refer - locator inversion of control (IoC) pattern
  • Run - component life-cycle management patterns

Quick links:

Use

Install the Python package as

pip install pip_services4_components

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_services4_commons.config import IConfigurable, ConfigParams
from pip_services4_commons.refer import IReferenceable, IReferences, Descriptor
from pip_services4_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, context):
        self._opened = True
        print("MyComponentA has been opened.")

    def close(self, context):
        self._opened = True
        print("MyComponentA has been closed.")

Then here is how the component can be used in the code

from pip_services4_commons.config import IConfigurable, ConfigParams
from pip_services4_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(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.

from pip_services4_commons.refer import Descriptor
from pip_services4_components.build import Factory


class MyFactory(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 factory
my_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"))

...

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 initial implementation is done by Sergey Seroukhov. Pip.Services team is looking for volunteers to take ownership over Python implementation in the project.

Metadata

Release files for pip-services4-components 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pip-services4-components 0.0.9
File Size Uploaded Provenance
pip_services4_components-0.0.9.tar.gz 29.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pip-services4-components 0.0.9
File Interpreter ABI Platform
pip_services4_components-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 76.8 kB

Release files / pip_services4_components-0.0.9.tar.gz

Download URL pip_services4_components-0.0.9.tar.gz
Size 29.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3aae0c3828e82982b65a355356cf9a11ba52fb78258bfdcfd083eaf9304634ef
BLAKE2b-256 checksum
How to use checksums
05b8d707111c749261f3200c8424516f7f48c698e467253fc8ddbc107cacc8ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Release files / pip_services4_components-0.0.9-py3-none-any.whl

Download URL pip_services4_components-0.0.9-py3-none-any.whl
Size 47.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c2df1bea1e16dfcbd177855528331d891cf6b7e96cfe5019571027dba45cd6a
BLAKE2b-256 checksum
How to use checksums
353a3ff1406ee3be3440025574fbfabce738f58fbd5222e57bb6b7b6216a5b0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Security for pip-services4-components 0.0.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page