Skip to content

Only load the IPython and Jupyter integration modules when Dash is im… - #4037

Open
brandonschabell wants to merge 1 commit into
plotly:devfrom
brandonschabell:lazy-ipython-import
Open

brandonschabell wants to merge 1 commit into
plotly:devfrom
brandonschabell:lazy-ipython-import

Conversation

@brandonschabell

Copy link
Copy Markdown
Contributor

Only load the IPython and Jupyter integration modules when Dash is imported inside IPython. This should roughly halve the time it takes to import dash in environments that have IPython installed, but not imported.

Contributor Checklist

  • I have broken down my PR scope into the following TODO tasks
    • task 1
    • task 2
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
    • this GitHub #PR number updates the dash docs
    • here is the show and tell thread in Plotly Dash community

Copilot AI balanced review requested due to automatic review settings October 2, 2026 23:35
@sonarqubecloud

sonarqubecloud Bot commented Oct 2, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The gate detects an imported IPython package rather than an active IPython shell.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Optimizes Dash startup by avoiding Jupyter integration imports outside IPython.

Changes:

  • Gates Jupyter dependencies behind IPython detection.
  • Adds subprocess-based import tests.
  • Documents the startup improvement.
File Description
dash/​_jupyter.py Adds conditional integration loading.
tests/​unit/​test_jupyter_import.py Tests import behavior inside and outside IPython.
CHANGELOG.md Records the performance improvement.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread dash/_jupyter.py
Comment on lines +18 to 21
if "IPython" not in sys.modules:
# Not inside IPython: skip the heavy imports, they double the cost of `import dash`.
raise ImportError
from IPython import get_ipython # type: ignore[attr-defined]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants