Detect dark mode in Jupyter environments
Project description
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:
- JupyterLab Settings: Checks
~/.jupyter/lab/user-settings/for theme configuration - VS Code Settings: When running in VS Code, checks both workspace and user settings
- JavaScript Detection: Uses IPython magic to inspect the DOM for theme classes
- 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jupyter_dark_detect-0.1.0.tar.gz.
File metadata
- Download URL: jupyter_dark_detect-0.1.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0358da684f1e36d0a869e839fa55dc1d9183cfc3ff228fe416d5132a7f36bcc
|
|
| MD5 |
ed740202511810a43504b68b45146b4b
|
|
| BLAKE2b-256 |
725b4e3fc83ffd16d502bf34a143f1c6453da0ffacf7d461e825c5926bbcaa09
|
File details
Details for the file jupyter_dark_detect-0.1.0-py3-none-any.whl.
File metadata
- Download URL: jupyter_dark_detect-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
198a7fa1270c6ce1ac2fd056cea9300e018bb8d04211de4c946cbe9e03e7a89d
|
|
| MD5 |
dbfc6ea76931f1db726b15c81f7a6513
|
|
| BLAKE2b-256 |
76c08cc378aad5ccfcc37adeda27d3864f20ea808ad5b63572f5b986a42a649c
|