Skip to main content

jupyter-dark-detect

Detect dark mode in Jupyter environments (Notebook, Lab, VS Code, etc.).

Installation

pip install jupyter-dark-detect

Usage

from jupyter_dark_detect import is_dark

# Check if Jupyter is running in dark mode
if is_dark():
    print("Dark mode is enabled!")
    # Use dark theme colors for visualizations
    bg_color = "#1e1e1e"
    text_color = "#d4d4d4"
else:
    print("Light mode is enabled!")
    # Use light theme colors for visualizations
    bg_color = "#ffffff"
    text_color = "#000000"

Features

  • Multiple detection strategies for maximum compatibility:

    • JupyterLab theme settings files
    • VS Code workspace and user settings
    • JavaScript-based DOM inspection
    • System preferences (macOS and Windows)
  • Zero configuration - just import and use

  • Lightweight with minimal dependencies (only requires IPython)

  • Cross-platform support for JupyterLab, Jupyter Notebook, VS Code, and more

How It Works

The package tries multiple detection methods in order:

  1. JupyterLab Settings: Checks ~/.jupyter/lab/user-settings/ for theme configuration
  2. VS Code Settings: When running in VS Code, checks both workspace and user settings
  3. JavaScript Detection: Uses IPython magic to inspect the DOM for theme classes
  4. System Preferences: Falls back to OS-level dark mode settings on macOS and Windows

Use Cases

  • Matplotlib/Plotly Visualizations: Automatically adjust plot colors based on theme
  • Rich Terminal Output: Style console output to match the notebook theme
  • Custom Widgets: Build theme-aware Jupyter widgets
  • Documentation: Generate screenshots that match the user's theme

Example: Matplotlib Integration

import matplotlib.pyplot as plt
from jupyter_dark_detect import is_dark

# Set style based on theme
plt.style.use('dark_background' if is_dark() else 'default')

# Your plotting code
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.title("Theme-Aware Plot")
plt.show()

Example: Plotly Integration

import plotly.graph_objects as go
from jupyter_dark_detect import is_dark

# Create theme-aware Plotly figure
fig = go.Figure()
fig.add_trace(go.Scatter(x=[1, 2, 3, 4], y=[1, 4, 9, 16]))

# Update layout based on theme
if is_dark():
    fig.update_layout(
        template="plotly_dark",
        paper_bgcolor="#1e1e1e",
        plot_bgcolor="#1e1e1e"
    )
else:
    fig.update_layout(
        template="plotly_white",
        paper_bgcolor="white",
        plot_bgcolor="white"
    )

fig.show()

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for jupyter-dark-detect 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jupyter-dark-detect 0.1.0
File Size Uploaded
jupyter_dark_detect-0.1.0.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jupyter-dark-detect 0.1.0
File Interpreter ABI Platform
jupyter_dark_detect-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.1 kB

Release files / jupyter_dark_detect-0.1.0.tar.gz

Download URL jupyter_dark_detect-0.1.0.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b0358da684f1e36d0a869e839fa55dc1d9183cfc3ff228fe416d5132a7f36bcc
BLAKE2b-256 checksum
How to use checksums
725b4e3fc83ffd16d502bf34a143f1c6453da0ffacf7d461e825c5926bbcaa09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.4.17

Release files / jupyter_dark_detect-0.1.0-py3-none-any.whl

Download URL jupyter_dark_detect-0.1.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
198a7fa1270c6ce1ac2fd056cea9300e018bb8d04211de4c946cbe9e03e7a89d
BLAKE2b-256 checksum
How to use checksums
76c08cc378aad5ccfcc37adeda27d3864f20ea808ad5b63572f5b986a42a649c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.4.17

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page