A flexible service locator for Python
svcs (pronounced services) is a dependency container for Python. It gives you a central place to register factories for types/interfaces and then imperatively acquire instances of those types with automatic cleanup and health checks.
It's suitable for implementing Inversion of Control using either dependency injection or service location while not requiring global state, decorators, or mangling of function signatures.
Benefits:
- Eliminates tons of repetitive boilerplate code,
- unifies acquisition and cleanups of services,
- provides full static type safety for them,
- simplifies testing through loose coupling,
- improves live introspection and monitoring with health checks.
The goal is to minimize the code for acquiring pluggable services to:
from svcs.your_framework import svcs_from
def view(request):
db, api, cache = svcs_from(request).get(Database, WebAPIClient, Cache)
... or less!
To a type checker, db has the type Database, api has the type WebAPIClient, and cache has the type Cache.
db, api, and cache will be automatically cleaned up when the request ends – it's context managers all the way down.
svcs comes with seamless integration for AIOHTTP, FastAPI, Flask, and Starlette. Even more community-supported integrations can be found in our project wiki.
While svcs also has first-class support for static typing, it is strictly optional and will always remain so. svcs also doesn't check your types at runtime. It only forwards the type you have asked for to the type checker. If you don't use a type checker, that information is ignored without any runtime overhead.
Read on in Why? or watch this short video if you're intrigued:
Project links
Release Information
Removed
-
The Pyramid integration. Maintenance within the main package has become too much of a burden, so it is now lives in its own package called svcs-pyramid.
Migrating is a pure rename: install
svcs-pyramid, then replaceimport svcswithimport svcs_pyramidandsvcs.pyramid.foo()withsvcs_pyramid.foo(). The registry and the container are still stored under the same keys, so nothing else changes. We will try to continue its maintenance for as long as its feasible.This is in line with our backwards-compatibility policy that has a provision for this exact case. #180
Added
-
FastAPI:
svcs.fastapi.get_registry()returns the registry of a running application, either from the application object itself or from a test client wrapping it. The newsvcs.fastapi.DepRegistrydependency (based onsvcs.fastapi.registry()) injects it into views. #186 -
Starlette:
svcs.starlette.get_registry()returns the registry of a running application, either from the application object itself or from a test client wrapping it. #186
Fixed
- Autowiring now evaluates Python 3.14+
typing.ForwardRefannotations before service lookup. #187
Credits
svcs is written by Hynek Schlawack and distributed under the terms of the MIT license.
The development is kindly supported by my employer Variomedia AG and all my fabulous GitHub Sponsors.
The Bestagon radar logo is made by Lynn Root, based on a Font Awesome icon. svcs has started out as a wrapper around wired by Michael Merickel and has been heavily influenced by it.
svcs for Enterprise
Available as part of the Tidelift Subscription.
The maintainers of svcs and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file svcs-26.2.0.tar.gz.
File metadata
- Download URL: svcs-26.2.0.tar.gz
- Upload date:
- Size: 915.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
129efb89586c2c52295ee00b00562af7d85d5535dad149534993e25fccbd76a6
|
|
| MD5 |
733f43018a67099549449e868e3d970f
|
|
| BLAKE2b-256 |
9b5e89463bf7613fe723801b8f7000f37c4c36486adcda0d115ca417e513c7cc
|
Provenance
The following attestation bundles were made for svcs-26.2.0.tar.gz:
Publisher:
pypi-package.yml on hynek/svcs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
svcs-26.2.0.tar.gz -
Subject digest:
129efb89586c2c52295ee00b00562af7d85d5535dad149534993e25fccbd76a6 - Sigstore transparency entry: 2580928186
- Sigstore integration time:
-
Permalink:
hynek/svcs@9c740a713d1a2a3d65d6aadfcf3e35f4cf352290 -
Branch / Tag:
refs/tags/26.2.0 - Owner: https://github.com/hynek
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-package.yml@9c740a713d1a2a3d65d6aadfcf3e35f4cf352290 -
Trigger Event:
release
-
Statement type:
File details
Details for the file svcs-26.2.0-py3-none-any.whl.
File metadata
- Download URL: svcs-26.2.0-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1f074f345195b961fbf29af07f6ce181f7598813793773db20cf43870949c81
|
|
| MD5 |
ca76da5a8cfba555a8719b75400491cc
|
|
| BLAKE2b-256 |
307557ff9e594ee14d0948d3a77546894c5eb89616eeb7d8989962d6bcd1557b
|
Provenance
The following attestation bundles were made for svcs-26.2.0-py3-none-any.whl:
Publisher:
pypi-package.yml on hynek/svcs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
svcs-26.2.0-py3-none-any.whl -
Subject digest:
a1f074f345195b961fbf29af07f6ce181f7598813793773db20cf43870949c81 - Sigstore transparency entry: 2580928215
- Sigstore integration time:
-
Permalink:
hynek/svcs@9c740a713d1a2a3d65d6aadfcf3e35f4cf352290 -
Branch / Tag:
refs/tags/26.2.0 - Owner: https://github.com/hynek
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-package.yml@9c740a713d1a2a3d65d6aadfcf3e35f4cf352290 -
Trigger Event:
release
-
Statement type: