nautechsystems/nautilus_trader · error · KeyError

Theme ' ' not found. Available themes: . Register custom…

Error message

Theme '{name}' not found.{suggestion_text} Available themes: {available}. Register custom themes with register_theme().

What it means

get_theme looks up the _THEMES registry of built-in and custom theme configurations. An unknown name raises a KeyError listing available themes plus up to 3 fuzzy 'Did you mean' suggestions (difflib.get_close_matches, cutoff 0.6).

Solutions

  1. Use one of the names printed in 'Available themes:'
  2. Adopt the 'Did you mean' suggestion (e.g. fix case: 'dark' not 'DARK')
  3. Register the custom theme first with register_theme()

Example fix

// before
theme = get_theme("Dark")  # KeyError, did you mean 'dark'?
// after
theme = get_theme("dark")
Defensive patterns

Strategy: try-catch

Validate before calling

from nautilus_trader.analysis.themes import _THEMES
if name not in _THEMES:
    name = "dark"

Type guard

def theme_exists(name: str) -> bool:
    from nautilus_trader.analysis.themes import _THEMES
    return isinstance(name, str) and name in _THEMES

Try / catch

try:
    theme = get_theme(name)
except KeyError:
    logger.warning(f"Theme '{name}' not found, using 'dark'")
    theme = get_theme("dark")

Prevention

When it happens

Trigger: Calling get_theme("DARK") when the builtin is "dark"; passing a theme name from config that was never registered via register_theme; a renamed builtin theme.

Common situations: Case sensitivity mistakes; YAML/JSON config with a stale theme name; copying theme names between projects with different custom themes.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/c77f1b1d21bf7b3d. Report an issue: GitHub.

Appendix: source

Thrown at python/nautilus_trader/analysis/themes.py:122

    -------
    dict[str, Any]
        Theme configuration dictionary with "template" and "colors" keys.

    Raises
    ------
    KeyError
        If the theme name is not registered.

    """
    _require_not_none(name, "name")

    if name not in _THEMES:
        available = ", ".join(_THEMES.keys())

        suggestions = get_close_matches(name, _THEMES.keys(), n=3, cutoff=0.6)
        suggestion_text = f" Did you mean: {', '.join(suggestions)}?" if suggestions else ""

        raise KeyError(
            f"Theme '{name}' not found.{suggestion_text} "
            f"Available themes: {available}. "
            f"Register custom themes with register_theme().",
        )

    theme = _THEMES[name].copy()
    theme["colors"] = theme["colors"].copy()
    return theme


def register_theme(name: str, template: str, colors: dict[str, str]) -> None:
    """
    Register a custom theme.

    Parameters
    ----------
    name : str
        The theme name for future reference.

View on GitHub (pinned to 18893faf8b)