Skip to main content

Jupyter kernel for Mojo

Project description

mojokernel

A Jupyter kernel for Mojo. Supports full variable persistence, function/struct definitions, and error handling across notebook cells.

NB: This is not an official Modular project. It's created by Jeremy Howard from Answer.AI and uses undocumented private symbols from mojo in ways that might turn out to be flaky or disappear in a future version. If Modular releases an official kernel that provides the same functionality, we'll archive this one and update these docs to point at that instead.

Install

We recommend uv which handles the Mojo package index automatically:

uv pip install mojokernel
mojokernel install --sys-prefix

With pip, install Mojo first (it's hosted on a separate index that pip can't discover automatically):

pip install modular --extra-index-url https://modular.gateway.scarf.sh/simple/
pip install mojokernel
mojokernel install --sys-prefix

Then select "Mojo" in Jupyter's kernel picker.

The pre-built wheel includes a compiled C++ server that talks directly to Mojo's LLDB -- no text parsing, fast and reliable. If the server binary isn't available for your platform, the kernel falls back to a pexpect-based engine that wraps mojo repl.

Pexpect fallback

The pexpect engine is used automatically if the C++ server binary isn't present (e.g. when installing from the sdist). It spawns mojo repl and parses its output. To force pexpect mode:

MOJO_KERNEL_ENGINE=pexpect jupyter lab

Building from source

To build the C++ server yourself (e.g. for development or an unsupported platform):

brew install llvm   # macOS; on Linux: apt install llvm-18-dev liblldb-18-dev
tools/build_server.sh

PTY server (backup)

A third engine variant (server/repl_server_pty.cpp) uses SBDebugger::RunREPL() with PTY I/O redirection. This is a fallback in case the EvaluateExpression approach breaks in a future Modular release.

Releases

mojokernel wheels are built against a specific Mojo version. Install the version matching your Mojo:

# Check your Mojo version
mojo --version          # e.g. "Mojo 0.26.1.0 (156d3ac6)" → version 26.1.0

# Install matching mojokernel
uv pip install mojokernel==26.1.0

Publishing a new release

The wheel version is determined automatically from the latest Mojo release (via mojokernel/_version.py). No manual version bumping needed.

When Mojo publishes a new version:

  1. Go to Actions > "Build and publish wheels" > Run workflow
  2. Set publish: true to upload to PyPI

The CI installs the latest Mojo, builds the C++ server, and produces platform wheels tagged with the detected Mojo version. Wheels are built for macOS (Apple Silicon) and Linux (x86_64).

Testing

uv pip install -e .
pytest -q

Architecture

mojokernel/
  kernel.py              -- Jupyter kernel (ipykernel subclass)
  engines/
    base.py              -- ExecutionResult dataclass
    pexpect_engine.py    -- pexpect-based engine (default)
    server_engine.py     -- C++ server engine client
server/
  repl_server.cpp        -- C++ server (EvaluateExpression + REPL mode)
  repl_server_pty.cpp    -- PTY-based backup server
  mojo_repl.cpp          -- thin REPL wrapper (RunREPL)
  json.hpp               -- nlohmann/json
tests/
  test_pexpect_engine.py -- pexpect engine tests
  test_server_execute.py -- server engine tests
  test_kernel.py         -- kernel integration tests
tools/
  build_server.sh        -- compile C++ binaries
  server_exec.py         -- send code to server (debugging tool)
  test.sh                -- run pytest

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

mojokernel-26.1.0.post1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distributions

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

mojokernel-26.1.0.post1-cp312-cp312-manylinux_2_34_x86_64.whl (177.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

mojokernel-26.1.0.post1-cp312-cp312-macosx_10_13_universal2.whl (840.7 kB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

File details

Details for the file mojokernel-26.1.0.post1.tar.gz.

File metadata

  • Download URL: mojokernel-26.1.0.post1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mojokernel-26.1.0.post1.tar.gz
Algorithm Hash digest
SHA256 888d52fc779e70c50969b0cfea5da91848b75959228b1605bbf513254fe407b9
MD5 a7e77ef9cbbc41dcf0f01b566e772b6c
BLAKE2b-256 4799071fdee1acc211247d7c44798fda21926c53a1cd072249f7ee4b09ca7eea

See more details on using hashes here.

Provenance

The following attestation bundles were made for mojokernel-26.1.0.post1.tar.gz:

Publisher: release.yml on AnswerDotAI/mojokernel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mojokernel-26.1.0.post1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mojokernel-26.1.0.post1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e76c073329f9a4c83b0b3a519aca2b3b2639acc7bf94554f8782ec89398e7e71
MD5 5e8867711ed1cca936e2d42afb75b5e3
BLAKE2b-256 f1d82251e82890bd6b06d3f0128029def95c55d8fc643ad45f230497dbe16ea2

See more details on using hashes here.

Provenance

The following attestation bundles were made for mojokernel-26.1.0.post1-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: release.yml on AnswerDotAI/mojokernel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mojokernel-26.1.0.post1-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for mojokernel-26.1.0.post1-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 4e7f8abb2e93177022fd215f7b5ec9ec46a94c7be15dab1908e54a1dcf76d8ea
MD5 eac34b203469b5287b1671840ffa6666
BLAKE2b-256 414f8edcef6cd64b87625fe70a6f5a2d801bbfffcad1f731ed6da4c445df7dbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for mojokernel-26.1.0.post1-cp312-cp312-macosx_10_13_universal2.whl:

Publisher: release.yml on AnswerDotAI/mojokernel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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