svcs is a flexible service locator for Python applications, simplifying dependency management and resource cleanup. It currently stands at version 25.1.0 and typically releases new versions every 1-2 months, incorporating bug fixes, minor features, and framework integrations.
pip install svcsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a service, register it with `svcs.Registry` using a factory function, and then acquire and use it via `svcs.Container`. It also shows the recommended practice of using a `with` statement for automatic container cleanup.
If you were passing context managers to `register_value()` and managing their lifecycle manually, explicitly add `enter=False` to `register_value()` calls to maintain the old behavior, or switch to `register_factory()` if you want `svcs` to manage it.
Always ensure containers are properly closed. The recommended way is to use `with svcs.Container(...) as container:` for automatic cleanup. For registries, ensure any registered context managers or asynchronous cleanups are explicitly managed.
Ensure the service is registered using `svcs.Container.register()` or `svcs.Container.register_factory()` before attempting to retrieve it with `svcs.Container.get()`.
Install the required extra using `pip install "svcs[fastapi]"`, and ensure you `from svcs.fastapi import svcs_from_request` when using it.
Ensure the class or object returned by the async factory implements `async def __aenter__(self):` and `async def __aexit__(self, exc_type, exc_val, exc_tb):` methods.
Ensure service retrieval happens within an active `svcs.Context` block, typically `with svcs.Container.get_abstract_context() as container: service = container.get(MyService)`. For framework integrations, use the provided dependency.
No dependency data recorded yet.