Skip to main content

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"

Release files for python-summer-boot 1.0.13

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

Source distribution (sdist)

Source distribution for python-summer-boot 1.0.13
File Size Uploaded
python-summer-boot-1.0.13.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-summer-boot 1.0.13
File Interpreter ABI Platform
python_summer_boot-1.0.13-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / python-summer-boot-1.0.13.tar.gz

Download URL python-summer-boot-1.0.13.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
da1184d697afc5195199e5184e13a245815538c93d4a0c006470fa48b5b9bfc9
BLAKE2b-256 checksum
How to use checksums
88c5dd427b349030dba39544d7ec29bdb8a576708c61a3968222d2a36ee23c54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Release files / python_summer_boot-1.0.13-py3-none-any.whl

Download URL python_summer_boot-1.0.13-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f49d1c1ea1b194f52bda1a826ebde8afa0011db032bedd15de561241b3c2e93
BLAKE2b-256 checksum
How to use checksums
eaaa354cc248f38fdb599f448b1abef12606d6e989e06d8d21f3fe74531578fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Release history Release notifications | RSS feed

This release

1.0.13 This release

2 release files

1.0.12

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

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