Skip to content

Conversation

@eh-steve
Copy link

@eh-steve eh-steve commented Jan 27, 2026

Implement lazy loading to speed up import times for packages that use this library

Closes #544


Contributor checklist:

  • I have read and understood CONTRIBUTING.md
  • Confirmed an issue exists for the PR, and the text Closes #issue appears in the PR summary (e.g., Closes #123).
  • Confirmed PR is rebased onto the latest base
  • Confirmed failure before change and success after change
  • Any generic new functionality is replicated across cloud providers if necessary
  • Tested manually against live server backend for at least one provider
  • Added tests for any new functionality
  • Linting passes locally
  • Tests pass locally
  • Updated HISTORY.md with the issue that is addressed and the PR you are submitting. If the top section is not `## UNRELEASED``, then you need to add a new section to the top of the document for your change.

Implements lazy loading via __getattr__ for all cloud provider classes.
This defers loading heavy cloud SDKs (google-cloud-storage, boto3,
azure-storage-blob) until they are actually accessed, significantly
reducing import time for applications that only use a subset of providers.

Key changes:
- cloudpathlib/__init__.py: Use __getattr__ to lazy-load all path/client classes
- cloudpathlib/s3/__init__.py: Use __getattr__ to lazy-load S3Client, S3Path
- cloudpathlib/gs/__init__.py: Use __getattr__ to lazy-load GSClient, GSPath
- cloudpathlib/azure/__init__.py: Use __getattr__ to lazy-load AzureBlobClient, AzureBlobPath
- cloudpathlib/cloudpath.py: Change absolute import to relative; move anypath import to function-local
- tests/test_import_time.py: Add tests verifying lazy loading behavior

TYPE_CHECKING blocks preserve static type hints for IDE support.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve import time by lazy-loading cloud provider modules

1 participant