Skip to main content

A plugin for Litestar to integrate `svcs`.

Project description

Litestar Svcs

A plugin to integrate litestar with svcs.

Basic Usage

from litestar import Litestar
from litestar import get
from litestar_svcs import SvcsPlugin, SvcsPluginConfig

from svcs import Container, Registry

@get("/", sync_to_thread=False)
def get_user(svcs_container: Container) -> int:
  return svcs_container.get(int)


registry = Registry()
registry.register_factory(int, lambda: 10)

svcs_plugin_config = SvcsPluginConfig(registry=registry)
svcs_plugin = SvcsPlugin(svcs_plugin_config)

app = Litestar([get_user], plugins=[svcs_plugin])

Configuring

  • You can pass in the registry instance, as in the example, to the config or you can give it a callable (sync or async) and it will be used to create the registry when the app is starting.

  • You can give a custom name to the name of the kwarg for injecting the containers by setting a different value for container_dependency_key (default is svcs_container).

    NOTE: You cannot configure the name of the kwarg which injects the registry (the kwarg name is svcs_registry).

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

litestar_svcs-0.1.2.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

litestar_svcs-0.1.2-py3-none-any.whl (4.2 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