Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hynek/svcs
A Flexible Service Locator for Python.
https://github.com/hynek/svcs
aiohttp dependency-injection fastapi flask inversion-of-control ioc pyramid python service-locator starlette
Last synced: 7 days ago
JSON representation
A Flexible Service Locator for Python.
- Host: GitHub
- URL: https://github.com/hynek/svcs
- Owner: hynek
- License: mit
- Created: 2023-07-12T08:43:28.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-17T11:38:24.000Z (26 days ago)
- Last Synced: 2024-11-29T20:02:00.400Z (14 days ago)
- Topics: aiohttp, dependency-injection, fastapi, flask, inversion-of-control, ioc, pyramid, python, service-locator, starlette
- Language: Python
- Homepage: https://svcs.hynek.me
- Size: 1.87 MB
- Stars: 308
- Watchers: 4
- Forks: 19
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
- awesome-dependency-injection-in-python - svcs - A Flexible Service Locator for Python. [🐍, MIT License]. (Software / DI Frameworks / Containers)
- awesome-litestar - SVCS - %E2%AD%90%20Enabled-202235.svg?logo=python&labelColor=202235&color=edb641&logoColor=edb641)](https://docs.litestar.dev/latest/usage/plugins.html) (Third-Party Extensions / General)
- stars - hynek/svcs - A Flexible Service Locator for Python. (Python)
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](https://svcs.hynek.me/en/latest/glossary.html#term-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:
```python
from svcs.your_framework import svcs_fromdef view(request):
db, api, cache = svcs_from(request).get(Database, WebAPIClient, Cache)
```... or less!
To a type checker like [Mypy](https://mypy-lang.org), `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?*](https://svcs.hynek.me/en/latest/why.html) or watch this short video if you're intrigued:
[![Watch the video](https://img.youtube.com/vi/d1elMD9WgpA/maxresdefault.jpg)](https://youtu.be/d1elMD9WgpA)
## Project Links
- [**PyPI**](https://pypi.org/project/svcs/)
- [**GitHub**](https://github.com/hynek/svcs)
- [**Documentation**](https://svcs.hynek.me)
- [**Changelog**](https://github.com/hynek/svcs/blob/main/CHANGELOG.md)
- [**Funding**](https://hynek.me/say-thanks/)
- [**Third-party extensions**](https://github.com/hynek/svcs/wiki/Third%E2%80%90party-Extensions)## Credits
*svcs* is written by [Hynek Schlawack](https://hynek.me/) and distributed under the terms of the [MIT](https://github.com/hynek/svcs/blob/main/LICENSE) license.
The development is kindly supported by my employer [Variomedia AG](https://www.variomedia.de/) and all my fabulous [GitHub Sponsors](https://github.com/sponsors/hynek).
The [Bestagon](https://www.youtube.com/watch?v=thOifuHs6eY) radar logo is made by [Lynn Root](https://www.roguelynn.com), based on an [Font Awesome](https://fontawesome.com) icon.
*svcs* has started out as a wrapper around [*wired*](https://wired.readthedocs.io/) by [Michael Merickel](https://michael.merickel.org/) and has been heavily influenced by it.