Lazy service definitions - #28
Merged
Merged
Conversation
Sebastian Packmann (sebastiandev)
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds lazy, per-service configuration loading to PyProvider.
Instead of parsing a single large YAML file during provider initialization, applications can split service definitions into individual YAML files backed by a small JSON manifest. Each service definition is parsed and cached only when that service is first requested.
Changes
service_provider_from_directory(...)for lazy service configuration loading.LazyServiceConfig, a mapping-compatible configuration source.split_service_definitions(...)to generate:manifest.jsonloaded_service_namesfor diagnostics and verification.get,set,reset, and attribute accessservice_provider_from_yaml(...)unchanged for backward compatibility.2.1.0.Generated Directory Format
Example manifest:
{ "format": 1, "provider_name": "core-provider", "services": { "auth-helper": "auth-helper.yaml", "orders.creator": "orders.creator.yaml" } }Provider initialization reads only
manifest.json:A service definition is loaded and parsed on first use:
Motivation
Large service configuration files were parsed eagerly during every application worker startup, even though most services were not needed immediately.
The directory-backed provider moves that work to first use while preserving the existing service construction semantics.
Performance
Measured against ShipHero's configuration containing approximately 1,503 services:
In containerized application startup measurements:
The broader worker-startup measurements improved by approximately 1.4 to 1.9 seconds in single local runs, although some of that difference may be attributable to normal startup and filesystem variance.
Compatibility
Existing consumers using
service_provider_from_yaml(...)are unaffected.Adoption is explicit:
Applications can migrate independently without changing decorators or service lookup behavior.
Testing
Follow-Up
After publishing
pyrovider==2.1.0, consuming applications should:service_provider_from_yaml(...)toservice_provider_from_directory(...).