A Flexible Service Locator for Python.
This is just a quick fix for a warning in AIOHTTP 3.9+.
Full changelog below!
This release would not be possible without my generous sponsors! Thank you to all of you making sustainable maintenance possible! If you would like to join them, go to https://github.com/sponsors/hynek and check out the sweet perks!
Variomedia AG (@variomedia), Tidelift (@tidelift), FilePreviews (@filepreviews), Daniel Fortunov (@asqui), Kevin P. Fleming (@kpfleming), and Sören Weber (@SoerenWeber).
Adam Hill (@adamghill), Dan Groshev (@si14), Magnus Watn (@magnuswatn), David Cramer (@dcramer), Moving Content AG (@moving-content), ProteinQure (@ProteinQure), Jesse Snyder (@jessesnyder), Rivo Laks (@rivol), Ionel Cristian Mărieș (@ionelmc), The Westervelt Company (@westerveltco), Philippe Galvan (@PhilippeGalvan), Birk Jernström (@birkjernstrom), Tim Schilling (@tim-schilling), Chris Withers (@cjw296), Christopher Dignam (@chdsbd), Stefan Hagen (@sthagen), Sławomir Ehlert (@slafs), Mostafa Khalil (@khadrawy), Filip Mularczyk (@mukiblejlok), Mike Fiedler (@miketheman), and Michel Vittória (@michelvittoria).
Not to forget 5 more amazing humans who chose to be generous but anonymous!
aiohttp.web.AppKey
s on the application. This is an implementation detail and shouldn't matter, but it fixes a warning on AIOHTTP 3.9 and later.The main feature of this release are container-local registries that allow you to define factories that are only valid for a container. For example, based on request metadata! Check out the docs for details.
There's one minor backward-incompatible change regarding the handling of values and context managers – please refer to https://github.com/hynek/svcs/discussions/50 for the reasons.
Finally there's a bunch of fixes around typing.
This release would not be possible without my generous sponsors! Thank you to all of you making sustainable maintenance possible! If you would like to join them, go to https://github.com/sponsors/hynek and check out the sweet perks!
Variomedia AG (@variomedia), Tidelift (@tidelift), FilePreviews (@filepreviews), Daniel Fortunov (@asqui), and Kevin P. Fleming (@kpfleming).
Adam Hill (@adamghill), Dan Groshev (@si14), Magnus Watn (@magnuswatn), David Cramer (@dcramer), Moving Content AG (@moving-content), ProteinQure (@ProteinQure), Jesse Snyder (@jessesnyder), Rivo Laks (@rivol), Ionel Cristian Mărieș (@ionelmc), The Westervelt Company (@westerveltco), Philippe Galvan (@PhilippeGalvan), Birk Jernström (@birkjernstrom), Tim Schilling (@tim-schilling), Chris Withers (@cjw296), Christopher Dignam (@chdsbd), Stefan Hagen (@sthagen), Sławomir Ehlert (@slafs), and Mostafa Khalil (@khadrawy).
Not to forget 5 more amazing humans who chose to be generous but anonymous!
Backwards-Incompatible: Since multiple people have been bit by the enter=True
default for Registry.register_value()
, and it's very early in svcs life, we're changing the default to enter=False
for all versions of register_value()
.
This means that you have to explicitly opt-in to context manager behavior which makes a lot more sense for singletons like connection pools which are the most common candidates for registered values.
(The irony of shipping a backwards-incompatible change in the release directly following the adoption of a backwards-compatibility policy not lost on me.) #50 #51
Container-local registries! Sometimes it's useful to bind a value or factory only to a container. For example, request metadata or authentication information.
You can now achieve that with svcs.Container.register_local_factory()
and svcs.Container.register_local_value()
. Once something local is registered, a registry is transparently created and it takes precedence over the global one when a service is requested. The local registry is closed together with the container. #56
Flask: svcs.flask.registry
which is a werkzeug.local.LocalProxy
for the currently active registry on flask.current_app
.
I'm very proud to hereby announce the first stable version of svcs.
I'm both excited and anxious how it's going to be received.
Please give it a shot and let me know!
This release would not be possible without my generous sponsors! Thank you to all of you making sustainable maintenance possible! If you would like to join them, go to https://github.com/sponsors/hynek and check out the sweet perks!
Variomedia AG (@variomedia), Tidelift (@tidelift), Sentry (@getsentry), HiredScore (@HiredScore), FilePreviews (@filepreviews), Daniel Fortunov (@asqui), and Kevin P. Fleming (@kpfleming).
Adam Hill (@adamghill), Dan Groshev (@si14), Magnus Watn (@magnuswatn), David Cramer (@dcramer), Moving Content AG (@moving-content), Stein Magnus Jodal (@jodal), ProteinQure (@ProteinQure), Jesse Snyder (@jessesnyder), Rivo Laks (@rivol), Tom Ballinger (@thomasballinger), Ionel Cristian Mărieș (@ionelmc), The Westervelt Company (@westerveltco), Philippe Galvan (@PhilippeGalvan), Birk Jernström (@birkjernstrom), Tim Schilling (@tim-schilling), Chris Withers (@cjw296), Christopher Dignam (@chdsbd), and Stefan Hagen (@sthagen).
Not to forget 3 more amazing humans who chose to be generous but anonymous!
Backwards-compatibility! svcs is pronounced stable now -- no more rug-pulls planned! #36
Flask: svcs.flask.container
which is a werkzeug.local.LocalProxy
(like, for example, flask.current_app
) and is the currently active container when accessed within a request context.
Just internal re-jiggerings.
With Starlette successfully added, I hope svcs is now feature-complete and won't need any bigger changes in the future.
I suspect it can be proclaimed stable soon, just when I realize how to market it…
Flask: svcs.flask.get_registry()
.
Starlette integration. #31
FastAPI integration has landed in #30!
enter keyword argument to all register_(value|factory)()
. It prevents svcs from entering context managers if the factory returns one. This is useful for context managers like database transactions that you want to start manually.
Services acquired using aget()
now also can receive the current container if they take one argument that is named svcs_container
or that is annotated as being svcs.Container
and has any name.
ResourceWarning
is now raised when a container or a registry are garbage-collected with pending cleanups.Cleanups for services are internally context managers now. For your convenience, if you pass an (async) generator function for a factory, the registry will automatically wrap it for you into an (async) context manager. #92
Pyramid: svcs.pyramid.get()
now takes a Pyramid request as the first argument. svcs.pyramid.get_pings()
also doesn't look at thread locals anymore. If you still want to use thread locals, you can use svcs.pyramid.from_svcs(None)
to obtain the currently active container.
Flask: replace_(value|factory)()
is now called overwrite_(value|factory())
to be consistent with the docs lingo. They also completely reset the instantiation cache now (practically speaking: they close the container).
svcs.Container.forget_about()
. It doesn't make any sense in a world of recursive dependencies. Just reset the container using svcs.Container.(a)close()
.AIOHTTP integration has landed!