pip-services4-components


Namepip-services4-components JSON
Version 0.0.9 PyPI version JSON
download
home_pagehttps://github.com/pip-services4/pip-services4-python/tree/main/pip-services4-components-python
SummaryComponent definitions for Pip.Services in Python
upload_time2024-09-09 12:04:13
maintainerNone
docs_urlNone
authorConceptual Vision Consulting LLC
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # <img src="https://uploads-ssl.webflow.com/5ea5d3315186cf5ec60c3ee4/5edf1c94ce4c859f2b188094_logo.svg" alt="Pip.Services Logo" width="200"> <br/> Portable Component Model for Python

This module is a part of the [Pip.Services](https://www.pipservices.org/) 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

<a name="links"></a> Quick links:

* [Logging](http://docs.pipservices.org/v4/tutorials/beginner_tutorials/observability/logging/)
* [Configuration](http://docs.pipservices.org/v4/tutorials/beginner_tutorials/configuration/) 
* [API Reference](https://pip-services4-python.github.io/pip-services4-components-python/index.html)
* [Change Log](CHANGELOG.md)
* [Get Help](http://docs.pipservices.org/v4/get_help/)
* [Contribute](http://docs.pipservices.org/v4/contribute/)

## Use

Install the Python package as
```bash
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.

```python
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

```python
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.

```python
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:
```bash
pip install -r requirements.txt
```

Run automated tests:
```bash
python test.py
```

Generate API documentation:
```bash
./docgen.ps1
```

Before committing changes run dockerized build and test as:
```bash
./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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pip-services4/pip-services4-python/tree/main/pip-services4-components-python",
    "name": "pip-services4-components",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Conceptual Vision Consulting LLC",
    "author_email": "seroukhov@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/05/b8/d707111c749261f3200c8424516f7f48c698e467253fc8ddbc107cacc8ba/pip_services4_components-0.0.9.tar.gz",
    "platform": "any",
    "description": "# <img src=\"https://uploads-ssl.webflow.com/5ea5d3315186cf5ec60c3ee4/5edf1c94ce4c859f2b188094_logo.svg\" alt=\"Pip.Services Logo\" width=\"200\"> <br/> Portable Component Model for Python\n\nThis module is a part of the [Pip.Services](https://www.pipservices.org/) polyglot microservices toolkit.\n\nIt defines a portable component model interfaces and provides utility classes to handle component lifecycle.\n\nThe module contains the following packages:\n- **Build** - basic factories for constructing objects\n- **Config** - configuration pattern\n- **Refer** - locator inversion of control (IoC) pattern\n- **Run** - component life-cycle management patterns\n\n<a name=\"links\"></a> Quick links:\n\n* [Logging](http://docs.pipservices.org/v4/tutorials/beginner_tutorials/observability/logging/)\n* [Configuration](http://docs.pipservices.org/v4/tutorials/beginner_tutorials/configuration/) \n* [API Reference](https://pip-services4-python.github.io/pip-services4-components-python/index.html)\n* [Change Log](CHANGELOG.md)\n* [Get Help](http://docs.pipservices.org/v4/get_help/)\n* [Contribute](http://docs.pipservices.org/v4/contribute/)\n\n## Use\n\nInstall the Python package as\n```bash\npip install pip_services4_components\n```\n\nThen you are ready to start using the Pip.Services patterns to augment your backend code.\n\nFor instance, here is how you can implement a component, that receives configuration, get assigned references,\ncan be opened and closed using the patterns from this module.\n\n```python\nfrom pip_services4_commons.config import IConfigurable, ConfigParams\nfrom pip_services4_commons.refer import IReferenceable, IReferences, Descriptor\nfrom pip_services4_commons.run import IOpenable\n\n\nclass MyComponentA(IConfigurable, IReferenceable, IOpenable):\n    _param1 = 'ABC'\n    _param2 = 123\n    _another_component: MyComponentB\n    _opened = True\n\n    def configure(self, config):\n        self._param1 = ConfigParams.get_as_string_with_default(\"param1\", self._param1)\n        self._param2 = config.get_as_integer_with_default(\"param2\", self._param2)\n\n    def set_references(self, references):\n        self._another_component = references.get_one_required(\n            Descriptor(\"myservice\", \"mycomponent-b\", \"*\", \"*\", \"1.0\")\n        )\n\n    def is_opened(self):\n        return self._opened\n\n    def open(self, context):\n        self._opened = True\n        print(\"MyComponentA has been opened.\")\n\n    def close(self, context):\n        self._opened = True\n        print(\"MyComponentA has been closed.\")\n```\n\nThen here is how the component can be used in the code\n\n```python\nfrom pip_services4_commons.config import IConfigurable, ConfigParams\nfrom pip_services4_commons.refer import References, Descriptor\n\nmy_component_A = MyComponentA()\n\n# Configure the component\nmy_component_A.configure(ConfigParams.from_tuples(\n    'param1', 'XYZ',\n    'param2', 987\n))\n\n# Set references to the component\nmy_component_A.set_references(References.from_tuples(\n    Descriptor(\"myservice\", \"mycomponent-b\", \"default\", \"default\", \"1.0\"), my_component_B\n))\n\n# Open the component\nmy_component_A.open(Context.from_trace_id(\"123\"))\nprint(\"MyComponentA has been opened.\")\n```\n\nIf you need to create components using their locators (descriptors) implement \ncomponent factories similar to the example below.\n\n```python\nfrom pip_services4_commons.refer import Descriptor\nfrom pip_services4_components.build import Factory\n\n\nclass MyFactory(Factory):\n    my_component_descriptor = Descriptor(\"myservice\", \"mycomponent\", \"default\", \"*\", \"1.0\")\n\n    def __init__(self):\n        super(MyFactory, self).__init__()\n\n        self.register_as_type(MyFactory.my_component_descriptor, MyFactory)\n\n\n# Using the factory\nmy_factory = MyFactory()\nmy_component1 = my_factory.create(Descriptor(\"myservice\", \"mycomponent\", \"default\", \"myComponent1\", \"1.0\"))\nmy_component2 = my_factory.create(Descriptor(\"myservice\", \"mycomponent\", \"default\", \"myComponent2\", \"1.0\"))\n\n...\n```\n\n## Develop\n\nFor development you shall install the following prerequisites:\n* Python 3.7+\n* Visual Studio Code or another IDE of your choice\n* Docker\n\nInstall dependencies:\n```bash\npip install -r requirements.txt\n```\n\nRun automated tests:\n```bash\npython test.py\n```\n\nGenerate API documentation:\n```bash\n./docgen.ps1\n```\n\nBefore committing changes run dockerized build and test as:\n```bash\n./build.ps1\n./test.ps1\n./clear.ps1\n```\n\n## Contacts\n\nThe initial implementation is done by **Sergey Seroukhov**. Pip.Services team is looking for volunteers to \ntake ownership over Python implementation in the project.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Component definitions for Pip.Services in Python",
    "version": "0.0.9",
    "project_urls": {
        "Homepage": "https://github.com/pip-services4/pip-services4-python/tree/main/pip-services4-components-python"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "353a3ff1406ee3be3440025574fbfabce738f58fbd5222e57bb6b7b6216a5b0b",
                "md5": "abca734354b359915f369aeaad1b53c3",
                "sha256": "2c2df1bea1e16dfcbd177855528331d891cf6b7e96cfe5019571027dba45cd6a"
            },
            "downloads": -1,
            "filename": "pip_services4_components-0.0.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "abca734354b359915f369aeaad1b53c3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 47788,
            "upload_time": "2024-09-09T12:04:12",
            "upload_time_iso_8601": "2024-09-09T12:04:12.522221Z",
            "url": "https://files.pythonhosted.org/packages/35/3a/3ff1406ee3be3440025574fbfabce738f58fbd5222e57bb6b7b6216a5b0b/pip_services4_components-0.0.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "05b8d707111c749261f3200c8424516f7f48c698e467253fc8ddbc107cacc8ba",
                "md5": "c9b51a1ce7ac074af73afb038de36718",
                "sha256": "3aae0c3828e82982b65a355356cf9a11ba52fb78258bfdcfd083eaf9304634ef"
            },
            "downloads": -1,
            "filename": "pip_services4_components-0.0.9.tar.gz",
            "has_sig": false,
            "md5_digest": "c9b51a1ce7ac074af73afb038de36718",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 29045,
            "upload_time": "2024-09-09T12:04:13",
            "upload_time_iso_8601": "2024-09-09T12:04:13.939437Z",
            "url": "https://files.pythonhosted.org/packages/05/b8/d707111c749261f3200c8424516f7f48c698e467253fc8ddbc107cacc8ba/pip_services4_components-0.0.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-09 12:04:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pip-services4",
    "github_project": "pip-services4-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pip-services4-components"
}
        
Elapsed time: 0.40654s