nautechsystems/nautilus_trader · error · KeyError
Theme '{name}' not found.{suggestion_text} Available themes:
Error message
Theme '{name}' not found.{suggestion_text} Available themes: {available}. Register custom themes with register_theme(). What it means
get_theme raises KeyError when the requested theme name is not in the _THEMES registry. Like the chart registry, it appends difflib close-match suggestions (cutoff 0.6) and the full available list; custom themes exist only after register_theme in the same process. This is the error surfaced when TearsheetConfig.theme names an unknown theme.
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 a4b06ed870)
Solutions
- Use the suggestion hint or pick from the Available list in the message
- List valid names: from nautilus_trader.analysis.themes import list_themes; print(list_themes())
- For custom themes, call register_theme(name, template, colors) at startup before any get_theme/config use
- Match casing exactly (built-ins are lowercase)
Example fix
# before
get_theme('nautilusdrak')
# KeyError: Theme 'nautilusdrak' not found. Did you mean: nautilus_dark? ...
# after
get_theme('nautilus_dark') Defensive patterns
Strategy: validation
Validate before calling
from nautilus_trader.analysis.themes import list_themes
if theme not in list_themes():
raise ValueError(f'Unknown theme {theme!r}; choose from {list_themes()}')
get_theme(theme) Type guard
from nautilus_trader.analysis.themes import list_themes
def is_registered_theme(name: object) -> bool:
return isinstance(name, str) and name in list_themes() Try / catch
try:
theme = get_theme(requested)
except KeyError as e:
# fallback to a built-in instead of failing the whole render
logger.warning('%s; falling back to plotly_white', e)
theme = get_theme('plotly_white') Prevention
- Call register_theme for custom themes once at process startup
- Treat theme names as case-sensitive constants defined near your config
- Cover theme resolution in a startup self-check: assert get_theme(cfg.theme)
When it happens
Trigger: get_theme('dark') (intended 'nautilus_dark'); TearsheetConfig(theme='plotly-black') typo; referencing a theme registered in a different run/process; theme names are case-sensitive, so 'Plotly_White' also fails.
Common situations: Hand-written theme strings in configs; themes renamed between nautilus_trader versions; assuming a custom theme registered in a notebook session persists to a fresh process.
Related errors
- No tearsheet chart registered under '{chart_name}'.{hint} Re
- {name} must not be None
- Theme name cannot be empty
- Colors dict missing required keys: {missing_keys}. Required
- Chart renderer must be callable, was {type(renderer)}
AI-assisted analysis of nautechsystems/nautilus_trader@a4b06ed870 (2026-08-16).
Data as JSON: /api/errors/c77f1b1d21bf7b3d.
Report an issue: GitHub.