Service injector to create multiple version of a service with ease and safety.
Project description
iservice
Helper class to make FastAPI dependencies with ease.
Simple use
# iservice_a.py
import typing
import iservice
class ServiceA(iservice.Service, typing.Protocol):
@staticmethod
def send(name: str) -> None: ...
# service_a1.py
def send(name: str) -> None:
print(f"Hello {name}")
# service_a2.py
def send(name: str) -> None:
print(f"Greetings {name}")
# service_a.py
import iservice_a
import service_a1
import service_a2
def _welcome_user(service: iservice_a.ServiceA, name: str) -> None:
service.send(name)
# inject will provide an inferred type that are matching the expected signature
# (str) -> None
hello = iservice.inject(_welcome_user, service_a1)
greeting = iservice.inject(_welcome_user, service_a2)
In this case, in case of incorrect calls, mypy will raise errors like:
hello(1) # Argument 1 has incompatible type "int"; expected "str"
greeting(1) # Argument 1 has incompatible type "int"; expected "str"
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
iservice-0.2.3.tar.gz
(11.6 kB
view hashes)