Skip to main content

svcs logo showing a hexagon-shaped radar

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:

Watch the video

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 replace import svcs with import svcs_pyramid and svcs.pyramid.foo() with svcs_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 new svcs.fastapi.DepRegistry dependency (based on svcs.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.ForwardRef annotations before service lookup. #187

Full Changelog →

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

svcs-26.2.0.tar.gz (915.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

svcs-26.2.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

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

Hashes for svcs-26.2.0.tar.gz
Algorithm Hash digest
SHA256 129efb89586c2c52295ee00b00562af7d85d5535dad149534993e25fccbd76a6
MD5 733f43018a67099549449e868e3d970f
BLAKE2b-256 9b5e89463bf7613fe723801b8f7000f37c4c36486adcda0d115ca417e513c7cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for svcs-26.2.0.tar.gz:

Publisher: pypi-package.yml on hynek/svcs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for svcs-26.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1f074f345195b961fbf29af07f6ce181f7598813793773db20cf43870949c81
MD5 ca76da5a8cfba555a8719b75400491cc
BLAKE2b-256 307557ff9e594ee14d0948d3a77546894c5eb89616eeb7d8989962d6bcd1557b

See more details on using hashes here.

Provenance

The following attestation bundles were made for svcs-26.2.0-py3-none-any.whl:

Publisher: pypi-package.yml on hynek/svcs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

26.2.0 This release

2 files

26.1.0

2 files

25.1.0

2 files

24.1.0

2 files

23.21.0

2 files

23.20.0

2 files

23.19.0

2 files

23.18.0

2 files

23.17.0

2 files

23.16.0

2 files

23.15.0

2 files

23.14.0

2 files

23.13.0

2 files

23.12.0

2 files

23.11.0

2 files

23.10.0

2 files

23.9.0

2 files

23.8.0

2 files

23.7.0

2 files

23.6.0

2 files

23.5.0

2 files

23.4.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page