Simple DI Framework for Python 3.x 🐍
Project description
BindMe
Simple DI Framework for Python 3.x 🐍
Usage
Installation Instructions:
To install the package, run:
pip install bindme
Features
Interesting Highlights:
Simple 📕 - everything you need is here!
Fast ⚡ - awesome work speed!
Low 🍃 - weighs nothing at all!
Use Cases
Examples:
project structure
# create interface
from abc import ABC, abstractmethod
from typing import Any, NoReturn
class ItemServiceInterface:
@abstractmethod
def create_one(self, dto: dict[str, Any]) -> NoReturn:
raise NotImplementedError("<create one> method is not implemented!")
@abstractmethod
def get_one(self, dto: dict[str, Any]) -> NoReturn:
raise NotImplementedError("<get one> method is not implemented!")
# create implement
from src.interfaces import ItemServiceInterface
class ItemServiceImplement(ItemServiceInterface):
def create_one(self, dto: dict[str, Any]) -> None:
print(f"Item with {dto} is created!")
def get_one(self, dto: dict[str, Any]) -> None:
print(f"Item with {dto} is get!")
# configure bindme
from bindme import container
from src.interfaces.item import ItemServiceInterface
from src.implements.item import ItemServiceImplement
container.register(abstract_class=ItemServiceInterface, concrete_class=ItemServiceImplement)
# use container directly from code
from bindme import container
from src.implements.item import ItemServiceInterface
def get_item_service():
item_service = container.resolve(abstract_class=ItemServiceInterface)
item_service.create_one({"name": "Bob"})
# item_service.get_one({"name": "Bob"})
get_item_service()
# use @injection decorator
from bindme import inject
from src.implements.item import ItemServiceInterface
@inject
def get_item_service(item_service: ItemServiceInterface):
item_service.create_one(dto={"name": "Bob"})
# item_service.get_one(dto={"name": "Bob"})
get_item_service(item_service=ItemServiceImplement)
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
bindme-0.3.0.tar.gz
(11.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
bindme-0.3.0-py3-none-any.whl
(13.9 kB
view details)
File details
Details for the file bindme-0.3.0.tar.gz.
File metadata
- Download URL: bindme-0.3.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a0137ea9752a69966fac947947726cece82eb3d0fb500f0138d5e2936a0853a
|
|
| MD5 |
79f0c5728018020528a48f58e0014a01
|
|
| BLAKE2b-256 |
5e5ace83e49f98abcc2ab1274e22608ceddfe7ef2b9f3d5523cc7eb77599acf3
|
File details
Details for the file bindme-0.3.0-py3-none-any.whl.
File metadata
- Download URL: bindme-0.3.0-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10f01cda8119b931be33653366e31291d7cb6a15614789e24a35900d26dfb478
|
|
| MD5 |
4327ce57eab265f918504d4c30137af9
|
|
| BLAKE2b-256 |
92174d4826b515f5edb45c25e8f8210137095ae1fd12ad7cd9aa503d52559b51
|