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 details)
Built Distribution
File details
Details for the file iservice-0.2.3.tar.gz
.
File metadata
- Download URL: iservice-0.2.3.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fb1e3f08b02d076fb549e272c6bd3c83928babc8c1409cba90551b21f075a92 |
|
MD5 | c325cefe3c4e814fe40efcd1654eeddd |
|
BLAKE2b-256 | 8008fb32967535673019ea0668e4e282608404274037d7d36adcbd71df68fbe2 |
File details
Details for the file iservice-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: iservice-0.2.3-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e574ad10c229dc87e6a5831148b3b9d9825dca98cbf51f9982d1677ce4a1135f |
|
MD5 | 569019213a0a76da3eb91d318cf987dc |
|
BLAKE2b-256 | 71801f7b473f377bba05ee21851b82229aacb996a8ed11a2ca4d4b62e998fc27 |