headroomlabs-ai/headroom · error · AttributeError

module {__name__!r} has no attribute {name!r}

Error message

module {__name__!r} has no attribute {name!r}

What it means

headroom.proxy is a lazily-imported package: only create_app and run_server are exposed via module-level __getattr__, which imports them from headroom.proxy.server on first access and caches the attribute. Any other attribute access raises a plain AttributeError with this message. This is a normal Python import-error path, so the fix is to import the real symbol from the submodule that defines it.

Source

Thrown at headroom/proxy/__init__.py:27

    # Use with Claude Code
    ANTHROPIC_BASE_URL=http://localhost:8787 claude

    # Use with Cursor (if using Anthropic)
    Set base URL in Cursor settings to http://localhost:8787
"""

__all__ = ["create_app", "run_server"]


def __getattr__(name: str) -> object:
    if name in ("create_app", "run_server"):
        from .server import create_app, run_server  # noqa: F811

        globals()["create_app"] = create_app
        globals()["run_server"] = run_server
        return globals()[name]
    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

View on GitHub (pinned to 322425c43b)

Solutions

  1. Import the symbol from its defining submodule, e.g. `from headroom.proxy.server import create_app, run_server`.
  2. If the symbol is a handler/helper, find its real module (headroom.proxy.handlers.*, headroom.proxy.helpers) and import from there.
  3. Check spelling first — only create_app and run_server are re-exported at package level.

Example fix

# before
from headroom.proxy import create_server  # AttributeError

# after
from headroom.proxy import run_server  # or: from headroom.proxy.server import create_app
Defensive patterns

Strategy: type-guard

Validate before calling

import headroom.proxy as hp

# only these two are re-exported lazily
assert set(hp.__all__) <= {"create_app", "run_server"}
symbol_ok = name in hp.__all__

Type guard

import headroom.proxy as hp

def is_proxy_export(name: str) -> bool:
    return name in getattr(hp, "__all__", ())

Try / catch

try:
    create_app = getattr(headroom.proxy, "create_app")
except AttributeError as exc:
    raise ImportError("import from headroom.proxy.server directly") from exc

Prevention

When it happens

Trigger: Accessing anything other than headroom.proxy.create_app or headroom.proxy.run_server — e.g. `from headroom.proxy import AnthropicHandler`, `headroom.proxy.config`, or a typo like `headroom.proxy.createServer`.

Common situations: IDE autocompleting a symbol that exists in a submodule but not at package level; porting code that imported from an older non-lazy layout; hasattr() checks triggering the __getattr__ and returning False for symbols that live in submodules.

Related errors


AI-assisted analysis of headroomlabs-ai/headroom@322425c43b (2026-08-15). Data as JSON: /api/errors/3803e1c2d74fc9d1. Report an issue: GitHub.