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 issvcs_container
).NOTE: You cannot configure the name of the kwarg which injects the registry (the kwarg name is
svcs_registry
).
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
Built Distribution
File details
Details for the file litestar_svcs-0.1.2.tar.gz
.
File metadata
- Download URL: litestar_svcs-0.1.2.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0e3260277b1696c76cf2b260d205ebae2f06ced4681ce55bd9d035328c34bd2 |
|
MD5 | 2382819dee474a80500e37f7fae541d4 |
|
BLAKE2b-256 | fa9f88a5ef7177aec6eb9cc26b9f55ce17c14d25da140037e27b9efeb662055d |
File details
Details for the file litestar_svcs-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: litestar_svcs-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1c49ffc6c4a7d876db40452040d3597273d6b417e305125479b730995a119c8 |
|
MD5 | 961bd4ea5996e5a7bc3df6615d37b3c7 |
|
BLAKE2b-256 | e6775a3520da54139bfce714694eeba96ce19828f4dcdfd5030b0edc2012ae53 |