diff --git a/pageindex/__init__.py b/pageindex/__init__.py index f90041e..ab4350d 100644 --- a/pageindex/__init__.py +++ b/pageindex/__init__.py @@ -9,15 +9,13 @@ _chatgpt_key = _os.getenv("CHATGPT_API_KEY") if not _os.getenv("OPENAI_API_KEY") and _chatgpt_key: _os.environ["OPENAI_API_KEY"] = _chatgpt_key -from typing import TYPE_CHECKING as _TYPE_CHECKING -if _TYPE_CHECKING: - # Static-only bindings for the lazy legacy names — real signatures for IDEs. - from .index.page_index import page_index, page_index_main, tree_parser - from .index.page_index_md import md_to_tree - from .index.utils import ConfigLoader, llm_completion, llm_acompletion - from .retrieve import get_document, get_document_structure, get_page_content +# Legacy (pre-SDK) exports. Cheap to import eagerly: litellm/PyPDF2 load +# inside the functions that use them, not at module import. +from .index.page_index import * # noqa: E402 +from .index.page_index_md import md_to_tree +from .retrieve import get_document, get_document_structure, get_page_content -# SDK exports — must stay light: no LLM/indexing imports here. +# SDK exports from .client import PageIndexClient, LocalClient, CloudClient from .config import IndexConfig, set_llm_params from .collection import Collection @@ -71,37 +69,11 @@ __all__ = [ "get_page_content", ] -# Legacy (pre-SDK) exports resolve lazily (PEP 562) so cloud-only -# `import pageindex` never pays for litellm/PyPDF2. -_LAZY_LEGACY = { - "md_to_tree": ".index.page_index_md", - "get_document": ".retrieve", - "get_document_structure": ".retrieve", - "get_page_content": ".retrieve", -} - def __getattr__(name): - if name.startswith("_"): - # dunder probes (pickle, IPython) must not trigger the heavy import - raise AttributeError(f"module {__name__!r} has no attribute {name!r}") - import importlib + # `pageindex.utils` / `pageindex.page_index_md` attribute access without an + # explicit submodule import. if name in ("utils", "page_index_md"): + import importlib return importlib.import_module(f".{name}", __name__) - module = _LAZY_LEGACY.get(name) - if module is not None: - value = getattr(importlib.import_module(module, __name__), name) - globals()[name] = value - return value - # Remaining pre-SDK names live in index.page_index (star-exports index.utils). - legacy = importlib.import_module(".index.page_index", __name__) - try: - value = getattr(legacy, name) - except AttributeError: - raise AttributeError(f"module {__name__!r} has no attribute {name!r}") from None - globals()[name] = value - return value - - -def __dir__(): - return sorted(set(globals()) | set(__all__) | {"utils", "page_index_md"}) + raise AttributeError(f"module {__name__!r} has no attribute {name!r}")