This document explains the current state of package management in Mojo as of January 2026.
TL;DR: Mojo has basic packaging capabilities but no centralized package registry yet. You can create and share packages, but distribution is manual.
A single .mojo file that can be imported:
# mymodule.mojo
struct MyStruct:
var value: Int
fn __init__(out self, value: Int):
self.value = value# main.mojo
from mymodule import MyStruct
def main():
var obj = MyStruct(42)Limitation: Module must be in same directory or you need packages.
A directory with an __init__.mojo file:
mypackage/
├── __init__.mojo # Makes this a package
├── module1.mojo
└── module2.mojo
# main.mojo
from mypackage import module1
from mypackage.module2 import SomeFunctionYou can compile a package into a distributable file:
mojo package mypackage -o mypackage.mojopkgThis creates a portable binary package that:
- Works across systems (architecture-independent)
- Contains non-elaborated code
- Can be imported like source packages
- More secure (obfuscated)
Usage:
# Import from compiled package
from mypackage import somethingMojo finds .mojopkg files in:
- Current directory
- Directories in
MOJO_LIBRARY_PATHenvironment variable
- No equivalent of PyPI, npm, crates.io
- Can't
mojo install package-name - Manual distribution only
- No
requirements.txtorCargo.tomlequivalent - No automatic dependency resolution
- Must manually manage dependencies
- No standard for version, author, license
- No semantic versioning enforcement
- No dependency declaration format
mojoCLI doesn't have package management commands (yet)- Must use external tools (pixi, conda, etc.)
Use pixi (Recommended by Modular):
# pixi.toml
[project]
name = "mojo-dotenv"
version = "0.1.0"
channels = ["conda-forge", "https://conda.modular.com/max-nightly"]
[dependencies]
mojo = "*"
[tasks]
test = "mojo test tests/"
build = "mojo package src/dotenv -o dotenv.mojopkg"pixi run test
pixi run buildBenefits:
- Virtual environment management
- Lock files for reproducibility
- Task runner built-in
- Works with conda ecosystem
Manual sharing:
-
Source code:
git clone https://github.com/user/mojo-dotenv # Copy src/ to your project -
Compiled package:
# Build mojo package src/dotenv -o dotenv.mojopkg # Share .mojopkg file # Users add to their project
-
Via GitHub releases:
- Tag version:
git tag v0.1.0 - Create GitHub release
- Attach
.mojopkgfile - Users download and import
- Tag version:
While there's no official standard, the community has converged on:
mypackage/
├── src/
│ └── mypackage/
│ ├── __init__.mojo # Package entry point
│ ├── module1.mojo
│ └── module2.mojo
├── tests/
│ ├── test_module1.mojo
│ └── test_module2.mojo
├── examples/
│ └── example.mojo
├── README.md
├── LICENSE
└── pixi.toml # Or magic.toml
Expose public API:
# src/mypackage/__init__.mojo
# Import from modules
from .module1 import PublicFunction1
from .module2 import PublicFunction2, PublicStruct
# Now users can:
# from mypackage import PublicFunction1, PublicStruct- Package names:
snake_caseorkebab-case - Module names:
snake_case.mojo - Compiled packages:
packagename.mojopkg
Based on Modular's roadmap and community discussions:
- Central repository for Mojo packages
- CLI commands:
mojo add,mojo install,mojo publish - Versioning and dependency resolution
- Package discovery and search
Likely similar to:
# mojoproject.toml (hypothetical)
[package]
name = "mojo-dotenv"
version = "0.1.0"
authors = ["Your Name <email@example.com>"]
license = "Apache-2.0"
description = "Load environment variables from .env files"
repository = "https://github.com/user/mojo-dotenv"
[dependencies]
# No dependencies
[dev-dependencies]
# Testing dependenciesModular's magic CLI (built on pixi) may become the official package manager:
magic add mojo-dotenv
magic install
magic run testsUse pixi:
# pixi.toml
[project]
name = "mojo-dotenv"
version = "0.1.0"
channels = ["conda-forge", "https://conda.modular.com/max-nightly"]
[dependencies]
mojo = "*"
python-dotenv = "*" # For testing
[tasks]
test = "mojo tests/test_basic.mojo"
build = "mojo package src/dotenv -o dotenv.mojopkg"
example = "mojo examples/simple.mojo"Via GitHub:
-
Source distribution:
# Users clone and copy git clone https://github.com/user/mojo-dotenv cp -r mojo-dotenv/src/dotenv /path/to/project/ -
Binary distribution:
# Build package mojo package src/dotenv -o dotenv.mojopkg # Create GitHub release gh release create v0.1.0 dotenv.mojopkg --title "v0.1.0" --notes "Initial release" # Users download curl -L -o dotenv.mojopkg https://github.com/user/mojo-dotenv/releases/download/v0.1.0/dotenv.mojopkg
-
Installation instructions:
## Installation ### Option 1: Source 1. Clone the repository 2. Copy `src/dotenv/` to your project 3. Import: `from dotenv import load_dotenv` ### Option 2: Compiled Package 1. Download `dotenv.mojopkg` from releases 2. Place in your project root or add to `MOJO_LIBRARY_PATH` 3. Import: `from dotenv import load_dotenv`
For users:
# Set library path (if needed)
export MOJO_LIBRARY_PATH="/path/to/packages:$MOJO_LIBRARY_PATH"
# Or add to shell profile
echo 'export MOJO_LIBRARY_PATH="/path/to/packages:$MOJO_LIBRARY_PATH"' >> ~/.zshrcFor now:
- ✅ Use pixi for development
- ✅ Structure as proper package with
__init__.mojo - ✅ Build
.mojopkgfor distribution - ✅ Share via GitHub releases
- ✅ Document installation clearly
Watch for:
- Official package registry announcement
magicCLI package management features- Standardized manifest format
Future-proof:
- Use semantic versioning
- Keep good documentation
- Follow community conventions
- Be ready to migrate to official registry
Last Updated: 2026-01-05