Skip to main content

Service injector to create multiple version of a service with ease and safety.

Project description

iservice

Supported Python versions Imports: isort PyPI - Downloads

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


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)

Uploaded Source

Built Distribution

iservice-0.2.3-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page