Skip to content

ImportError: OBBject_EquityInfo not found in provider_interface (v4.6.0) #7379

@zincsamael

Description

@zincsamael

Bug Description

After installing openbb==4.6.0 (or 4.5.0/4.3.5) with openbb-core==1.6.0, importing any module fails:

from openbb import obb
obb.equity.price.quote("AAPL", provider="yfinance")
# ImportError: cannot import name 'OBBject_EquityInfo' from 'openbb_core.app.provider_interface'

The auto-generated package files (e.g. openbb/package/equity.py) contain:

from openbb_core.app.provider_interface import (
    OBBject_EquityInfo,
    OBBject_EquityScreener,
    ...
)

But ProviderInterface.return_annotations creates these types dynamically and never registers them as module-level attributes on openbb_core.app.provider_interface.

The "Building..." rebuild on first import also fails to regenerate correct package files.

Environment

  • Python 3.12.3 (macOS arm64)
  • openbb 4.6.0, openbb-core 1.6.0
  • Installed via uv pip install openbb

Root Cause

package_builder.py generates from openbb_core.app.provider_interface import OBBject_X because the dynamically created types have __module__ == "openbb_core.app.provider_interface". But the types only exist in the return value of ProviderInterface.return_annotations, not as module attributes.

Fix

Add a __getattr__ hook at the end of openbb_core/app/provider_interface.py:

_cached_annotations = None

def __getattr__(name: str):
    if name.startswith("OBBject_"):
        global _cached_annotations
        if _cached_annotations is None:
            pi = ProviderInterface()
            _cached_annotations = pi.return_annotations
        model_name = name[len("OBBject_"):]
        if model_name in _cached_annotations:
            return _cached_annotations[model_name]
    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

This lazily resolves OBBject_* types when imported, matching the pattern the package builder generates. Tested and confirmed working.

Workaround

The REST API server (openbb-api) works fine since it does not use the generated package imports.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions