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.2.0.tar.gz
(10.7 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
File details
Details for the file bindme-0.2.0.tar.gz.
File metadata
- Download URL: bindme-0.2.0.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5b64a0231064073e94085008769ddb4cb2a5595b76ef15799a3e14270f1a030
|
|
| MD5 |
2adeb3c2a966f7db476bb89745ca5da5
|
|
| BLAKE2b-256 |
fd44bcaaf19f03b0b605bb0609e1f951f6ea1510dd9f2b6afd8cfbbca4ec1407
|
File details
Details for the file bindme-0.2.0-py3-none-any.whl.
File metadata
- Download URL: bindme-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.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 |
c9db6c0d7534b700a97d3608037b4d5f3eb9d29489a59b54b99d6857a79fb3f2
|
|
| MD5 |
f0a4d67fb3ef0d76d951099418cb1c1d
|
|
| BLAKE2b-256 |
5eb6faa817d46419f71c7469b20824f49c34798a2850d4adf51002d2d831d527
|