Skip to main content

A Flexible Service Locator

Project description

svcs logo showing a hexagon-shaped radar

A Flexible Service Locator for Python.

WARNING ☠️ Not ready yet! ☠️

This project is only public to gather feedback, and everything can and will change until the project is proclaimed stable.

The code has 100% test and type coverage, and the shipped Flask and Pyramid integrations have been in production for years, but the API details can still change.

svcs (pronounced services) is a dependency container for Python. It gives you a central place to register factories for types/interfaces and then imperatively request instances of those types with automatic cleanup and health checks.

It's a flexible Inversion-of-Control container that can be used for dependency injection or service location, but doesn't require 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,
  • and allows for easy health checks across all services.

The goal is to minimize the code for acquiring pluggable services to:

def view(request):
    db, api, cache = request.svcs.get(Database, WebAPIClient, Cache)

It's ensured that to a type checker like Mypy, db has the type Database, api has the type WebAPIClient, and cache has the type Cache.

svcs comes with seamless integration for the Flask and Pyramid web frameworks and has first-class async support.

While svcs 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?, if you find that intriguing!

Project Links

Release Information

Changed

  • Factory results of None are now treated like every other result and cached. #22

  • Calling Container.get() on a service that has an async factory now raises a TypeError. #21

Added

  • API reference docs!

  • A huge glossary that should have been a book. #20


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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

svcs-23.11.0.tar.gz (122.9 kB view details)

Uploaded Source

Built Distribution

svcs-23.11.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file svcs-23.11.0.tar.gz.

File metadata

  • Download URL: svcs-23.11.0.tar.gz
  • Upload date:
  • Size: 122.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for svcs-23.11.0.tar.gz
Algorithm Hash digest
SHA256 9a730a2ec28f4f4903040ccf64f51c31253dd8683b04e33c8a5e7b8f929f82e8
MD5 e0a056d3a20426747c428254ffeed82f
BLAKE2b-256 03dddc583fd529d1bcb5304c44d2d4c8d92413da8c72dcd27b8a932b9341c277

See more details on using hashes here.

File details

Details for the file svcs-23.11.0-py3-none-any.whl.

File metadata

  • Download URL: svcs-23.11.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for svcs-23.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c467c06837a5eddd96a870265a8f65be5c6ef1cb63a88dcae568d649cc4fd59
MD5 28d5f25572e012c817e84ae448e13b99
BLAKE2b-256 0bfe441cd00a7694f76e3637339c418b13910f8c1fbb9b86493fd12c8ee8825f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page