svcs

25.1.0last stable release 2 months ago
Complexity Score
Low
Open Issues
N/A
Dependent Projects
6
Weekly Downloadsglobal
8,309

License

  • MIT
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Nopatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Readme

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 like Mypy, 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, Pyramid, and Starlette.

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

  • PyPI
  • GitHub
  • Documentation
  • Changelog
  • Funding
  • Third-party extensions

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 an Font Awesome icon. svcs has started out as a wrapper around wired by Michael Merickel and has been heavily influenced by it.

Dependencies

No runtime dependency information found for this package.

CVE IssuesActive
0
Scorecards Score
No Data
Test Coverage
No Data
Follows Semver
No
Github Stars
322
Dependenciestotal
0
DependenciesOutdated
0
DependenciesDeprecated
0
Threat Modelling
No Data
Repo Audits
No Data

Learn how to distribute svcs in your own private PyPI registry

pip install svcs
Processing...
Done

22 Releases

PyPI on Cloudsmith

Getting started with PyPI on Cloudsmith is fast and easy.