A collection of sample programs and Mojo notebooks written in the Mojo programming language.
Access a Mojo programming environment available from the Mojo product page.
Git clone the repository of Mojo samples using the command below:
git clone https://github.com/modularml/mojo.git
If you're using magic
, navigate into
the examples directory and use magic run
. For example:
magic run mojo matmul.mojo
You can run the Mojo notebooks using JupyterLab or Visual Studio Code with the Mojo extension available on the Marketplace.
The repo also contains a Dockerfile that can be used to create a Mojo SDK container for developing and running Mojo programs. Use the container in conjunction with the Visual Studio Code devcontainers extension to develop directly inside the container.
The Dockerfile also sets up a conda
environment and by default,
starts a jupyter
server (which you can access via the browser).
To build a Mojo container, either use
docker-compose in mojo/examples/docker
:
docker compose up -d
Or the convenience script provided:
./build-image.sh --auth-key <your-modular-auth-key> \
--mojo-version 0.3
The script also supports building with podman
instead of docker
:
./build-image.sh --auth-key <your-modular-auth-key> \
--use-podman \
--mojo-version 0.3
You can then run with either docker
or podman
. In the example below,
we map the ports, bind mount the current directory and open a shell into
the container:
docker run \
-it --rm \
-p 8888:8888 \
--net host \
-v ${PWD}:${PWD} \
modular/mojo-v0.3-20232109-1205 bash
podman
requires an additional argument to add the SYS_PTRACE
capabilities:
podman run \
--cap-add SYS_PTRACE \
-it --rm \
-p 8888:8888 \
--net host \
-v ${PWD}:${PWD} \
modular/mojo-v0.3-20232109-1205 bash
The Mojo examples and notebooks in this repository are licensed under the Apache License v2.0 with LLVM Exceptions (see the LLVM License).
As a contributor, your efforts and expertise are invaluable in driving the evolution of the Mojo programming language. The Mojo contributor guide provides all the information necessary to make meaningful contributions—from understanding the submission process to adhering to best practices: