Skip to main content

No project description provided

Project description

moutils

Utility functions used in marimo.

[!NOTE] This is a community led effort and not actively prioritized by the core marimo team.

Installation

pip install moutils

or with uv:

uv add moutils

Widgets

Widget Description
URLHash Get and set the URL hash
URLPath Get and set the URL path
URLInfo Read all URL components
DOMQuery Query DOM elements with CSS selectors
CookieManager Get, set, and monitor browser cookies
StorageItem Read/write localStorage or sessionStorage
Slot Render HTML with DOM event handlers
CopyToClipboard Copy text to clipboard with a button
ShellWidget Run terminal commands with live output
ColorScheme Detect dark/light mode preference
ViewportSize Detect window dimensions
OnlineStatus Detect network connectivity
PageVisibility Detect if the browser tab is active
Geolocation Get the user's geographic coordinates
CameraCapture Capture a still image from the webcam
Notification Send browser notifications
KeyboardShortcut Listen for global keyboard shortcuts
PrintPageButton Button to open the browser print dialog
print_page() Programmatically trigger the browser print dialog
ScreenshotButton Button to capture a DOM element as PNG
screenshot() Programmatically screenshot a DOM element

URLHash

Get and set the hash portion of the URL.

from moutils import URLHash
h = URLHash()
h.hash  # e.g. "#section-1"

URLPath

Get and set the current URL path.

from moutils import URLPath
p = URLPath()
p.path  # e.g. "/notebooks/demo"

URLInfo

Read all URL components (protocol, hostname, port, pathname, search, hash, etc.).

from moutils import URLInfo
info = URLInfo()
info.hostname  # e.g. "localhost"

DOMQuery

Query DOM elements using CSS selectors.

from moutils import DOMQuery
q = DOMQuery(selector=".my-class")
q.result  # list of matched element data

CookieManager

Get, set, and monitor browser cookies.

from moutils import CookieManager
cm = CookieManager()
cm.cookies  # dict of current cookies

StorageItem

Read and write data in the browser's localStorage or sessionStorage.

from moutils import StorageItem
s = StorageItem(key="my-key", storage_type="local")
s.data  # stored value

Slot

Render HTML content and handle DOM events (mouse, keyboard, form, drag, touch, pointer, scroll, clipboard, animation).

from moutils import Slot
s = Slot(children="<button>Click me</button>", on_dblclick=lambda e: print(e))

CopyToClipboard

Copy text to the clipboard with a button and success feedback.

from moutils import CopyToClipboard
c = CopyToClipboard(text="hello world")

ShellWidget

Run terminal commands in notebooks with real-time output streaming.

from moutils import shell

shell("ls -la")
shell("npm install", working_directory="./frontend")

ColorScheme

Detect the user's preferred color scheme (light or dark). Automatically updates when the preference changes.

from moutils import ColorScheme
cs = ColorScheme()
cs.scheme       # "light" or "dark"
cs.prefers_dark # True or False

ViewportSize

Detect the browser window dimensions. Updates on resize (debounced).

from moutils import ViewportSize
vs = ViewportSize()
vs.width   # e.g. 1920
vs.height  # e.g. 1080

OnlineStatus

Detect whether the browser has network connectivity.

from moutils import OnlineStatus
os_ = OnlineStatus()
os_.online  # True or False

PageVisibility

Detect whether the browser tab is currently active or hidden.

from moutils import PageVisibility
pv = PageVisibility()
pv.visible  # True or False
pv.state    # "visible" or "hidden"

Geolocation

Get the user's geographic coordinates. Opt-in — set enabled=True to request permission.

from moutils import Geolocation
geo = Geolocation(enabled=True)
geo.latitude   # e.g. 37.7749
geo.longitude  # e.g. -122.4194
geo.accuracy   # meters
geo.error      # error message, if any

CameraCapture

Capture a still image from the webcam. Opt-in — set enabled=True to request camera access.

from moutils import CameraCapture
cam = CameraCapture(enabled=True, width=640, height=480)
cam.image_data  # base64 data URL of the captured image

Notification

Send browser notifications. Automatically requests permission when needed.

from moutils import Notification
n = Notification(title="Done!", body="Your computation finished.")
n.send = True   # fires the notification
n.permission    # "default", "granted", or "denied"

KeyboardShortcut

Listen for global keyboard shortcuts with modifier key support.

from moutils import KeyboardShortcut
ks = KeyboardShortcut(shortcut="ctrl+k")
ks.pressed  # True when the shortcut is pressed
ks.event    # dict with key event details

PrintPageButton

Button that opens the browser print dialog when clicked.

from moutils import PrintPageButton
btn = PrintPageButton()

print_page()

Programmatically trigger the browser print dialog.

import moutils
moutils.print_page()

ScreenshotButton

Button that captures a DOM element as a PNG and downloads it.

from moutils import ScreenshotButton
btn = ScreenshotButton(locator="#my-chart", filename="chart.png")

screenshot()

Programmatically screenshot a DOM element and download as PNG.

import moutils
moutils.screenshot(locator="#my-chart", filename="chart.png")

Development

We use uv for development.

Specific notebook

uv run marimo edit notebooks/example.py

Workspace

uv run --active marimo edit --port 2718

Installing pre-commit

uv tool install pre-commit
pre-commit

Testing

To run all tests:

pytest -v tests/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moutils-0.4.1.tar.gz (145.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

moutils-0.4.1-py3-none-any.whl (59.3 kB view details)

Uploaded Python 3

File details

Details for the file moutils-0.4.1.tar.gz.

File metadata

  • Download URL: moutils-0.4.1.tar.gz
  • Upload date:
  • Size: 145.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for moutils-0.4.1.tar.gz
Algorithm Hash digest
SHA256 9d0cfe1878928f0b621e6b4a9840c1baf0fbbd4d2e9f1432d30499b9552497ed
MD5 15f32cc03f9e68a78e7a6cf6e02d4839
BLAKE2b-256 f0ae1b625809a35628048ae94af499152ef2520670af969c6d070304dc4d1a0f

See more details on using hashes here.

File details

Details for the file moutils-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: moutils-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 59.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for moutils-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f5a0490b97c4e9fd1e0dad3d1f27ce60b25d7563a6dd7e124720a112796fdebf
MD5 e679efbb284d7b9b18447f8fc2a8fb59
BLAKE2b-256 1d503ff7c9f685beeefb62a1bf2f73de45f36738e81fdd8113f36bd8c30e86d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page