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.
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jupyter_dark_detect-0.1.0.tar.gz | 7.2 kB | Without provenance | Details for jupyter_dark_detect-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jupyter_dark_detect-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for jupyter_dark_detect-0.1.0-py3-none-any.whl |
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
|
Security for jupyter-dark-detect 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.