Highlights
In the spirit of "we do these things not because they are easy, but because we thought they were going to be easy" this release brings a great new feature: autowiring!
It resolves dependencies based on type annotations and allows you to shed boilerplate when registering nested services. Check out its docs for details!
Since this release took way too long (to the point of leaving another great feature for later 😢), there's a too many features and bug fixes to list, so check out the full changelog below!
Special Thanks
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!
Above and Beyond
Variomedia AG (@variomedia), Tidelift (@tidelift), Kraken Tech (@kraken-tech), Klaviyo (@klaviyo), Privacy Solutions GmbH (@privacy-solutions), FilePreviews (@filepreviews), Ecosystems (@ecosyste-ms), Doist (@Doist), Daniel Fortunov (@asqui), and Kevin P. Fleming (@kpfleming).
Maintenance Sustainers
Buttondown (@buttondown), Christopher Dignam (@chdsbd), Magnus Watn (@magnuswatn), David Cramer (@dcramer), Rivo Laks (@rivol), Polar (@polarsource), Mike Fiedler (@miketheman), Duncan Hill (@cricalix), Colin Marquardt (@cmarqu), Pieter Swinkels (@swinkels), Nick Libertini (@libertininick), Brian M. Dennis (@crossjam), Al Sweigart (@asweigart), Celebrity News AG (@celebritynewsag), The Westervelt Company (@westerveltco), Sławomir Ehlert (@slafs), Mostafa Khalil (@khadrawy), Filip Mularczyk (@mukiblejlok), Thomas Klinger (@thmsklngr), Andreas Poehlmann (@ap--), August Trapper Bigelow (@atbigelow), Carlton Gibson (@carltongibson), and Roboflow (@roboflow).
Full Changelog
Deprecated
svcs.get_abstract()and all its*_abstract()siblings. Thanks to PEP 747 they are no longer necessary. No deprecation warnings or plans to remove them for now.
Added
-
Python 3.14 and 3.15 support.
-
PEP 747 support, aka
typing.TypeForm. This means that it's now possible use abstract types likeProtocols or abstract base classes for registered services, removing an important typing caveat. This change introduces a dependency ontyping-extensionsfor Python 3.14 and earlier.Note: On Mypy versions older than 2.2, users that want to take advantage of this must pass the
--enable-incomplete-feature=TypeFormargument. -
New
svcs.autowire()andsvcs.aautowire()that can be used to automatically resolve dependencies based on type annotations. #167 -
New suppress_context_exit argument to
svcs.register_(factory|value)(). If set toFalse, errors in the container context will be passed into the factory cleanup context manager and allow you to act on them there.You can't stop the exception from bubbling out of the container context, though. #129
Removed
-
Debug logs don't contain stack information anymore since it leads to excessive output. If you miss them, please open an issue and we make it an option on
svcs.Registry. #135 #139 -
Python 3.9 support. #152
Changed
Container.get_pings()now includes registry-local services. Locally defined services overwrite global ones if they are registered for the same type. This includes that a local service without a ping disables a global service's ping. #83
Fixed
-
Factories now can return
MagicMocks without crashing with a TypeError. #137 -
AIOHTTP: The container is now stored using
aiohttp.web.RequestKeys on the application. This is an implementation detail and shouldn't matter, but it fixes a warning on AIOHTTP 3.14 and later.
This release contains contributions from @g0di, @hynek, @lewicki, and @vladfedoriuk.
Artifact Attestations
You can verify this release's artifact attestions using GitHub's CLI tool by downloading the sdist and wheel from PyPI and running:
$ gh attestation verify --owner hynek svcs-26.1.0.tar.gzand
$ gh attestation verify --owner hynek svcs-26.1.0-py3-none-any.whl