Skip to content

yggdrasil.lazy_imports

lazy_imports

Single guard module for optional dependencies.

Every other yggdrasil module reaches optional packages through here instead of through a per-package lib.py shim. Two access shapes:

  • from yggdrasil.lazy_imports import polars — direct attribute access via :func:__getattr__, lazily resolving on first touch. The result is the live module, identical to import polars.
  • from yggdrasil.lazy_imports import polars_module and call — identical effect, kept for callers that want the import to be a function call (clearer in long-import-graph code).

Probe helpers (has_X) are non-raising — they return False when the package isn't installed.

spark_dataframe_classes cached

spark_dataframe_classes() -> tuple[type, ...]

Tuple of Spark DataFrame classes for isinstance checks.

On PySpark 3.5 and earlier, pyspark.sql.connect.dataframe.DataFrame (the class Databricks Connect / Spark Connect sessions return from spark.sql(...)) is not a subclass of pyspark.sql.DataFrame — they are parallel implementations with duck-type-compatible APIs. A bare isinstance(obj, pyspark.sql.DataFrame) check rejects a perfectly valid Connect DataFrame. PySpark 4.0 collapsed both onto a common ancestor, so the tuple is redundant there but still correct.

Use:

from yggdrasil.lazy_imports import spark_dataframe_classes
if isinstance(obj, spark_dataframe_classes()):
    ...

spark_column_classes cached

spark_column_classes() -> tuple[type, ...]

Tuple of Spark Column classes for isinstance checks.

Same Connect / classic split as :func:spark_dataframe_classespyspark.sql.connect.column.Column is not a subclass of pyspark.sql.Column on PySpark 3.5 and earlier.

botocore_module

botocore_module(*, install: bool = False)

Lazy-import botocore.

We want the top-level botocore module so callers can reach botocore.exceptions, botocore.config, botocore.credentials, and botocore.session without triggering separate imports. Touches the four submodules we use after the parent loads so each is registered in sys.modules for cheap attribute access on later calls.

has_polars

has_polars() -> bool

Probe-only — never raises.