Skip to main content

A Lightweight Service Locator

Project description

svcs logo showing a hexagon-shaped radar

A Lightweight 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 service locator 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.

Benefits:

  • Eliminates tons of repetitive boilerplate code,
  • unifies acquisition and cleanups of resources,
  • provides full static type safety for them,
  • simplifies testing through loose coupling,
  • and allows for easy health checks across all resources.

The goal is to minimize the code for acquiring pluggable resources in your business code 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

Added

  • Proper documentation at https://svcs.hynek.me/! I guess it's getting serious. #17

  • Pyramid integration.

    Please note that not all integrations will be shipped with svcs proper once it is stable. Some will be moved to separate packages and Pyramid is a prime contender for that.


→ 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 locator 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.10.0.tar.gz (118.8 kB view details)

Uploaded Source

Built Distribution

svcs-23.10.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for svcs-23.10.0.tar.gz
Algorithm Hash digest
SHA256 6f4431f14d523cc6b96a0ceabf448f2b004dcf39ed0e009553cf6e9fc263b2a8
MD5 e2717507cfde0dafe80c956077979a36
BLAKE2b-256 258fc2d1b1d97adf9003abf3e0e33f8d7d5945bbd18d3094eff81be3d7fc6277

See more details on using hashes here.

File details

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

File metadata

  • Download URL: svcs-23.10.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 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.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f9a01d3cb8fa42b11af315314810aa59a8afee466747cbf4573db80796898b9
MD5 291bedd4361d8e54ce5bb132d9f89319
BLAKE2b-256 fcd95e6fafc8af3b830c04cdf39097a9f81c95425fc738875e1f83231001cbb3

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