Skip to content

Test lazy imports in __init__ - #6

Closed
keithpeck wants to merge 4 commits into
mainfrom
test-lazy-imports
Closed

Test lazy imports in __init__#6
keithpeck wants to merge 4 commits into
mainfrom
test-lazy-imports

Conversation

@keithpeck

@keithpeck keithpeck commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Problem
Importing earthdaily.earthone (or any of its eagerly-loaded sub-packages such as auth) triggered the immediate loading of all sub-packages. The vector sub-package transitively imports geopandas, pandas, and shapely at module level — all of which are expensive to initialise. This caused significant cold-start latency in environments that only need a lightweight sub-package (e.g. a Lambda function using only auth for token management).

Change
All sub-packages except config are now imported lazily using the PEP 562 module-level __getattr__ mechanism. They are loaded on first access rather than at package initialisation time.

config remains eagerly imported as it is required at module load time to assign the top-level select_env and get_settings helpers.

A module-level __dir__ has also been added, returning __all__, so that IDE tab-completion and dir() introspection continue to show lazy sub-packages even before they have been accessed.

Options considered
I considered adding a preload() function to allow opt-in eager loading but doesn't seem to be a common practice. users can achieve the same result with standard Python:

import earthdaily.earthone.catalog
import earthdaily.earthone.compute
import earthdaily.earthone.vector

Adding a named function would expand the public API surface for no meaningful benefit.

@keithpeck keithpeck changed the title Test lazy imports for catalog, compute, vector modules Test lazy imports in __init__ Jun 30, 2026
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.

1 participant