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.5.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63cdf1853f17effd2ff4ede101e1995491cf0e21044b5d6abff155b2e37f7b30 |
|
MD5 | 690b443f7238a3bd806e7ea81d17d03f |
|
BLAKE2b-256 | b8131453edfb1f7e97a9f8402a9d618ee1ebb9a233ac07a0855a0ae7f1c3b1b0 |
Hashes for python_summer_boot-1.0.5.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d05a0113f82ee7f2a464d76c5c8f49c7de0d6982e086d96ead2893ff7e3e5d75 |
|
MD5 | 200c474744623835f1287bc7e1c94970 |
|
BLAKE2b-256 | f08b66df51761943b0d6e0b262c446901e48b5f04e40dbabe3adc4949ae45d0f |