Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved lazy-export regressions break API discovery and existing module access, while concurrent API-key loading can overwrite explicitly assigned credentials.
3 open issues
What changed in this PR
This PR reduces import overhead for API and endpoint clients by deferring serverless worker dependencies and credential lookup until first use.
Changes:
- Adds lazy resolution for package exports and imports the worker when
start()runs. - Defers version metadata imports and API-key loading, preserving explicit key assignment and reload behavior.
- Adds isolated-process tests for import weight, export availability, and credential resolution.
| File | Description |
|---|---|
tests/test_lazy_imports_worker.py |
Adds import-weight and compatibility regression tests. |
runpod/version.py |
Loads metadata helpers only when needed. |
runpod/serverless/utils/__init__.py |
Resolves utility exports lazily. |
runpod/serverless/__init__.py |
Defers worker and selected helper imports. |
runpod/__init__.py |
Adds lazy CLI access and first-read API-key resolution. |
Review effort: Balanced
deanq
force-pushed
the
deanq/SLS-1129-lazy-imports-worker
branch
3 times, most recently
from
December 4, 2026 00:18
736295e to
6660c56
Compare
`import runpod.serverless` loaded aiohttp, the http client, the upload and download helpers and the credential parsers even for processes that only register hooks or read the version. Resolve those on first access instead (PEP 562), keeping every existing name importable: - serverless: worker, progress_update, VolumeCache and utils load lazily - serverless.utils: download/upload/VolumeCache load lazily - runpod.api_key is read from the credential store on first access, not at import (assignment and reload behave as before) - runpod.version: importlib.metadata is only touched when the generated _version module is absent - runpod.cli resolves lazily as an attribute Adds subprocess guard tests for the absence of heavy modules and for the public names staying resolvable.
- runpod.api_key: first read uses setdefault so a key assigned by another thread while the credential store is read is not overwritten - runpod.serverless and runpod.serverless.utils: add __dir__ listing the lazy exports without importing them - runpod.serverless.utils: resolve the rp_download, rp_upload and rp_volume_cache submodule attributes lazily, as the former eager imports exposed them; __all__ is unchanged
deanq
force-pushed
the
deanq/SLS-1129-lazy-imports-worker
branch
from
December 4, 2026 20:29
6660c56 to
e17a894
Compare
This branch has not been deployed
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
import runpodloaded the whole serverless worker stack (aiohttp, fastapi, the job loop) even for callers that only use the API client or the endpoint client. This defers those imports until they are used.Changes
runpod/__init__.py,runpod/serverless/__init__.pyandrunpod/serverless/utils/__init__.pyexpose the same names through module__getattr__(PEP 562) instead of eager imports.runpod.serverless.start()imports the worker when it is called.runpod.versionis resolved lazily.runpod.api_keyis read from the environment on first access instead of at import.Impact
Python 3.13, median wall time including interpreter start:
import runpodimport runpod.serverlessBehavior change
RUNPOD_API_KEYset afterimport runpodbut before the first read ofrunpod.api_keyis now picked up. Assigningrunpod.api_keyexplicitly works as before.Tests
New
tests/test_lazy_imports_worker.py(18 tests) checks which modules each import loads and that every public name still resolves. 9 failed before the change. Full suite passes.