After spring it comes the summer.
Project description
summer-boot
After spring it comes the summer.
Installation
pip install python-summer-boot
Inversion of control
summer-boot provides an easy dependency injection by splitting classes between services and injectors. A service is a dependency and an injector is a class that consumes dependencies.
You can discover services with the disvover_services
function.
It is recommended to create a setup file located in your sources root and call discover services function there, once.
Here you have an example:
import os
from summer.inversion_of_control.service_locator import get_executable_parent_path, discover_services
executable_parent_path = get_executable_parent_path(os.getcwd())
def setup():
discover_services(executable_parent_path)
⚠️ Remember to call setup function before use any injection. ⚠️
You can define services using the @service
decorator at class level.
from summer.inversion_of_control.dependencies import service
from src.mock_entity.core.i_repository import IRepository
@service()
class PostgreRepository(IRepository):
def custom_method(self):
return "Postgre repository"
Here the code of IRepository
:
from abc import ABC, abstractmethod
class IRepository(ABC):
@abstractmethod
def custom_method(self) -> str:
raise NotImplementedError
Finally, you can consume injected dependencies with the @autowired
decorator, upside the function that needs
dependencies. In most of the cases it will be the __init__
function:
from summer.inversion_of_control.dependencies import autowired
from src.mock_entity.core.i_repository import IRepository
class UseCase:
@autowired
def __init__(self, repository: IRepository):
self.repository = repository
def my_use_case(self) -> str:
return self.repository.custom_method()
Models
⚠️ It is necessary to install pydantic in order to use this module. ⚠️
SummerBoot implements some models using inheritance from pydantic.
CamelModel
A model which every attribute is represented as camelCase perhaps is coded as snake_case. I.e.:
from summer.models.camel.camel_model import CamelModel
class MockCamelModel(CamelModel):
mock_attribute: str = "mock"
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
Built Distribution
Hashes for python-summer-boot-1.0.12.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 974f65934db6d452fa15923cfdabb250940cc40cfead1c37829de02ca624ef21 |
|
MD5 | 29feeaa9a16907ba046e314c017389ef |
|
BLAKE2b-256 | 75363a8b5c72549bc29a448c43ce67efcd4cd6f6aa74fca19a312b6b980d9365 |
Hashes for python_summer_boot-1.0.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05f644d3c2c02fee622521bf2dc047d2192e1f75c01a8644f8d4f9738b343703 |
|
MD5 | e486192d0d80e1a7f639b25f577cf3dd |
|
BLAKE2b-256 | f0bc13898afa3a432198a05515b8913fdc02fac7869873538c0002cf112b2ee5 |