Building a .mojopkg
Bundle a package for reuse.
Building a .mojopkg is a free Mojo Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Mojo Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
From Files to a Package
Sharing loose files is fragile. Mojo lets you bundle a folder of modules into one tidy package artifact. 📦
A Package Is a Folder
A package is a directory of related modules treated as a single importable unit, much like a folder of files.
The __init__ Marker
A folder becomes a package when it holds an __init__.mojo file. That file marks the directory as importable.
Bundle It Up
The mojo package command compiles that folder into one distributable file you can hand to others.
mojo package mypkg -o mypkg.mojopkgThe .mojopkg File
The result is a .mojopkg file. It is a compiled bundle of your modules, ready to share or ship.
Import the Package
Anyone with your .mojopkg on the import path can use it just like a normal module they wrote themselves.
from mypkg import addFolder or File, Same Import
The same import works whether the package is a source folder or a compiled .mojopkg. You can switch freely.
Why Compile a Package
A packaged build is one compiled file instead of many sources, so it loads fast and is simpler to distribute.
Set the Output Name
The -o flag picks the output filename. Without it, the package keeps its directory name with a .mojopkg suffix.
Finding the Package
Mojo looks for imports on its import path. Place the .mojopkg where your project searches and the import resolves.
Share With Confidence
A single .mojopkg is the clean way to give your library to a teammate or another project. 🚀
Quick Check
Let us nail down how a folder becomes a package.
Recap
A package is a folder of modules with __init__.mojo. Run mojo package to compile it into one shareable .mojopkg. 🎯
Frequently asked questions
Is the “Building a .mojopkg” lesson free?
Yes — the full text of “Building a .mojopkg” is free to read here on the web, and the Mojo Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Mojo Academy course, upgrade to CoddyKit PRO.
What will I learn in “Building a .mojopkg”?
Bundle a package for reuse. You practise Mojo Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Mojo Academy?
No prior experience is required. Mojo Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Building a .mojopkg” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Mojo Academy lesson?
Yes. Every Mojo Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Modules and Imports
- Building a .mojopkg
- Public APIs and Structure
- Project Layout Best Practices