1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.
IoC container for Python
This module is a part of the Pip.Services polyglot microservices toolkit. It provides an inversion-of-control (IoC) container to facilitate the development of services and applications composed of loosely coupled components.
The module containes a basic in-memory container that can be embedded inside a service or application, or can be run by itself. The second container type can run as a system level process and can be configured via command line arguments. Also it can be used to create docker containers.
The containers can read configuration from JSON or YAML files use it as a recipe for instantiating and configuring components. Component factories are used to create components based on their locators (descriptor) defined in the container configuration. The factories shall be registered in containers or dynamically in the container configuration file.
The module contains the following packages:
- Containers - Basic in-memory and process containers
- Build - Default container factory
- Config - Container configuration components
- Refer - Inter-container reference management (implementation of the Referenceable pattern inside an IoC container)
- Test - minimal set of test components to make testing easier
Use
Install the Python package as
pip install pip_services4_container
Create a factory to create components based on their locators (descriptors).
from pip_services4_commons.refer import Descriptor
from pip_services4_components.build import Factory
class MyFactory(Factory):
MyComponentDescriptor = Descriptor("myservice", "mycomponent", "default", "*", "1.0")
def __init__(self):
super(MyFactory, self).__init__()
self.register_as_type(MyFactory.MyComponentDescriptor, MyComponent)
Then create a process container and register the factory there. You can also register factories defined in other modules if you plan to include external components into your container.
from pip_services4_container import ProcessContainer
from pip_services3_rpc.build import DefaultRpcFactory
class MyProcess(ProcessContainer):
def __init__(self):
super(MyProcess, self).__init__('myservice', 'My service running as a process')
self._factories.add(DefaultRpcFactory())
self._factories.add(MyFactory())
Define YAML configuration file with components and their descriptors. The configuration file is pre-processed using Handlebars templating engine that allows to inject configuration parameters or dynamically include/exclude components using conditional blocks. The values for the templating engine are defined via process command line arguments or via environment variables. Support for environment variables works well in docker or other containers like AWS Lambda functions.
---
# Context information
- descriptor: "pip-services:context-info:default:default:1.0"
name: myservice
description: My service running in a process container
# Console logger
- descriptor: "pip-services:logger:console:default:1.0"
level: {{LOG_LEVEL}}{{^LOG_LEVEL}}info{{/LOG_LEVEL}}
# Performance counters that posts values to log
- descriptor: "pip-services:counters:log:default:1.0"
# My component
- descriptor: "myservice:mycomponent:default:default:1.0"
param1: XYZ
param2: 987
{{#if HTTP_ENABLED}}
# HTTP endpoint version 1.0
- descriptor: "pip-services:endpoint:http:default:1.0"
connection:
protocol: "http"
host: "0.0.0.0"
port: {{HTTP_PORT}}{{^HTTP_PORT}}8080{{/HTTP_PORT}}
# Default Status
- descriptor: "pip-services:status-service:http:default:1.0"
# Default Heartbeat
- descriptor: "pip-services:heartbeat-service:http:default:1.0"
{{/if}}
To instantiate and run the container we need a simple process launcher.
import sys
from MyFactory import MyFactory
try:
proc = MyProcess()
proc._config_path = './config/config.yml'
proc.run()
except Exception as ex:
sys.stderr.write(ex)
And, finally, you can run your service launcher as
python service.py
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 Python version of Pip.Services is created and maintained by Sergey Seroukhov
Metadata
Release files for pip-services4-container 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
File added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release files before installing.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pip_services4_container-0.0.1.tar.gz | 19.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pip_services4_container-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 45.1 kB
Release files / pip_services4_container-0.0.1.tar.gz
| Download URL | pip_services4_container-0.0.1.tar.gz |
|---|---|
| Size | 19.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab32df2ffcc87fa25d495123c864b5cd25d6929988fd9a75abb1078326edd91a
|
|
BLAKE2b-256 checksum How to use checksums |
056b5f02b101eb02483903277c4b6674235588d83448eaf14ecb2a24e5338a61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.11
|
Release files / pip_services4_container-0.0.1-py3-none-any.whl
File added late
This file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release file before installing.
| Download URL | pip_services4_container-0.0.1-py3-none-any.whl |
|---|---|
| Size | 25.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7f619ff1333779c91b8b5eef2965f73bebde35c4fdae6acbd938504225afa17
|
|
BLAKE2b-256 checksum How to use checksums |
bcb41717d31b153231891db84ebed187c703c3ebab221a52c35185f77e0dacd0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for pip-services4-container 0.0.1
Upload timing
File added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
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.