Skip to content

ImportError: ArrowSerializer imported unconditionally but pyarrow not in deps #41

@27Bslash6

Description

@27Bslash6

Bug Description

When installing cachekit without pyarrow, importing the package fails:

ImportError: pyarrow is not installed. ArrowSerializer requires the [data] extra: pip install 'cachekit[data]'

Root Cause

cachekit/serializers/__init__.py line 7 unconditionally imports ArrowSerializer:

from .arrow_serializer import ArrowSerializer

But pyarrow is not in the required dependencies - it's supposed to be optional.

Expected Behavior

import cachekit should work without pyarrow installed. ArrowSerializer should be lazily imported or guarded.

Reproduction

pip install cachekit  # or uv add cachekit
python -c "from cachekit import cache"
# ImportError: pyarrow is not installed...

Environment

  • cachekit version: 0.3.0
  • Python: 3.13
  • OS: Linux

Suggested Fix

Option 1: Lazy import in __init__.py:

def __getattr__(name):
    if name == "ArrowSerializer":
        from .arrow_serializer import ArrowSerializer
        return ArrowSerializer
    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Option 2: Guard with try/except:

try:
    from .arrow_serializer import ArrowSerializer
except ImportError:
    ArrowSerializer = None  # type: ignore

Option 3: Add pyarrow to required deps (not recommended - adds 150MB).

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