Public APIs and Structure
Decide what to expose.
Public APIs and Structure is a free Mojo Academy lesson on CoddyKit — lesson 3 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.
What You Show Matters
A good library is judged by its surface. Deciding what to expose shapes how easy your API is to use. 🚪
Your Public API
The functions and types other code is meant to call form your public API. It is the promise you keep to users.
Internals Stay Hidden
Helper code that supports your API but is not meant for callers is internal. Hiding it keeps your surface small.
Smaller Surface, Less Risk
The fewer names you expose, the easier the library is to learn and the more freely you can change internals later.
Re-export From __init__
A package's __init__.mojo can import key names so users reach them straight from the package, not deep files.
from .core import add, subtractA Clean Front Door
By gathering imports in __init__, you give callers one clear entry point instead of long, fragile module paths.
from mypkg import addHide the Layout
Users import from the package, not its files. That lets you rearrange inner modules without breaking their code.
Name Things Clearly
Public names should be self-explanatory. A clear, stable name is part of the contract you do not want to change.
Document the Surface
Add a docstring to each public function and type. Good docs tell callers how to use the API correctly.
fn add(a: Int, b: Int) -> Int:
"""Return the sum of a and b."""
return a + bStable Promises
Treat your public API as a contract. Changing it can break users, so keep it small and think before you grow it.
Design From Outside In
Picture how a caller wants to use your library first, then build the internals to serve that clean experience. 🎨
Quick Check
Let us think about keeping an API easy to maintain.
Recap
Expose a small, clear public API, re-export key names in __init__, hide internals, and document what you share. 🎯
Frequently asked questions
Is the “Public APIs and Structure” lesson free?
Yes — the full text of “Public APIs and Structure” 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 “Public APIs and Structure”?
Decide what to expose. 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 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Public APIs and Structure” 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