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"
Metadata
Release files for iservice 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| iservice-0.2.3.tar.gz | 11.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| iservice-0.2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.4 kB
Release files / iservice-0.2.3.tar.gz
| Download URL | iservice-0.2.3.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0fb1e3f08b02d076fb549e272c6bd3c83928babc8c1409cba90551b21f075a92
|
|
BLAKE2b-256 checksum How to use checksums |
8008fb32967535673019ea0668e4e282608404274037d7d36adcbd71df68fbe2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / iservice-0.2.3-py3-none-any.whl
| Download URL | iservice-0.2.3-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e574ad10c229dc87e6a5831148b3b9d9825dca98cbf51f9982d1677ce4a1135f
|
|
BLAKE2b-256 checksum How to use checksums |
71801f7b473f377bba05ee21851b82229aacb996a8ed11a2ca4d4b62e998fc27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|