Your first module
A module is a folder with a manifest, a handler class, and optionally a page. Scaffold one, run it on the lite stack, build its page in the Studio, test it, and ship it.
Module folder#
modules/my_module/
├── manifest.yaml # required – identity, requirements, dependencies, frontend
├── module.py # required – one Module subclass, instantiated once per process
├── HOW_TO_USE.md # required – the user guide, shown behind the "How to use" button
├── events.py # recommended – Pydantic payload shapes you emit
├── tests/ # pytest
├── layout.json # the module page as a card grid, built in the Studio
├── panel/index.tsx # optional – a TSX module page, for custom interaction
├── widgets/*.tsx # dashboard cards
├── uv.lock # commit it – pins your Python dependencies
├── .venv/ · .dist/ · node_modules/ # created by the platform, gitignored
└── README.md # optional – developer notes (provenance, method, setup); not shown in the app
Commit the manifest, module.py, HOW_TO_USE.md, tests, layout.json, frontend sources, and uv.lock. Everything else is rebuilt.
Create a module in six steps#
Needs uv, pnpm (Node) and Python 3.12; see Contributing.
New — scaffold the folder.
PANEL=1also writespanel/index.tsx; the id must be snake_case and the folder must not exist. The scaffold passes validation as written: amanifest.yaml(in_process, onesummarytable output with atopparam), amodule.py(GET/summaryplus a POST/recountjob), aHOW_TO_USE.md, alayout.jsonwith one card of each common kind, andtests/test_my_module.py.Terminal make install # once: uv + pnpm dependencies make new ID=my_module # = uv run mate-module new my_module [--panel]Run — start the lite stack with only your module loaded and leave it running, then open the sample log and the module. No Docker and no
.env: you are signed in as an admin demo user, a sample log (120 cases) is imported on first start, and data lives underdata/lite/. Hard dependencies are added toMODULESautomatically; leave it out to load every module.Terminal make lite MODULES=my_module # API + bundler + web on :8000 / :3000; Ctrl-C stops all threeBuild the page — open Dev in the sidebar (
/dev), then Open Studio. Save writesmodules/my_module/layout.json— see The Studio. Editmodule.py,manifest.yamlandHOW_TO_USE.mdalongside. Savingmodule.pyormanifest.yamlreloads the module;HOW_TO_USE.mdis read fresh on every request.Test — in a second terminal,
make test ID=my_modulerunsmodules/my_module/tests— see Testing and publishing.Validate —
make validatechecks every module's manifest, guide andlayout.json, and exits1on any problem.Ship — open a pull request that commits the folder (it becomes a bundled module). Archive upload under Modules → Install a module works in lite mode and where
MODULE_UPLOAD_ENABLED=true; it is off by default, because uploaded code is not sandboxed. A new bundled module also needs its manual page: runmake docsand commitlanding/docs/site/.
The how-to-use guide#
Every module ships HOW_TO_USE.md next to its manifest, in one fixed format. It is compulsory: an upload without a valid guide is rejected, and the test suite checks every bundled module. The platform shows that one file in two places: the How to use button on the module page, and the Module guides section of this manual.
# How to use My Module
One short paragraph: the question the module answers and what you get back.
## When to use it
## Before you start
## Settings
## Reading the results
## Tips and limits
## Method
make new writes a valid, filled-in HOW_TO_USE.md; edit it in place. Only a module not created with make new starts from the template. Then check it; the checker lists every problem with its line number and exits 1 if there is any.
cp modules/HOW_TO_USE.template.md modules/my_module/HOW_TO_USE.md # only without make new
uv run mate-module validate modules/my_module # or: make validate
A bundled module's guide is also its page in this manual: run make docs after changing it.
The title must read # How to use <the manifest name>, all six sections are required in this order, and Settings is a Setting | Default | What it changes table (or the sentence "This module has no settings."). The same file renders in the app and here, so the format is a small markdown subset: absolute links only, no images, no HTML, no nested lists. modules/README.md has the full rules and what belongs in each section.
A minimal module that computes a result#
from mate.sdk import Module, ModuleContext, job, on_event, route
class MyModule(Module):
id = "my_module" # must equal manifest.id
async def _compute(self, ctx: ModuleContext) -> dict:
async with ctx.event_log as log:
rows = await log.duckdb_fetch(
"SELECT activity, count(*) AS events FROM events GROUP BY 1 ORDER BY 2 DESC LIMIT 10"
)
return {"top_activities": [{"activity": a, "events": n} for a, n in rows]}
@route.get("/top-activities")
async def top_activities(self, ctx: ModuleContext) -> dict:
cached = await ctx.cache.get("top_activities")
if cached is not None:
return cached
result = await self._compute(ctx)
await ctx.cache.set("top_activities", result)
return result
@on_event("log.imported")
@job(progress=True, title="My Module - precompute")
async def precompute(self, ctx: ModuleContext, payload: dict) -> None:
await ctx.progress.update(0.1, "Loading log")
await ctx.cache.set("top_activities", await self._compute(ctx))
await ctx.progress.update(1.0, "Done")
id: my_module
name: My Module
version: 0.1.0
category: attribute
description: Lists the most frequent activities in the log.
license: MIT
requirements:
event_log:
log_model: case_centric
required_columns: [case_id, activity, timestamp]
min_events: 1
provides: [my_module.top_activities]
consumes: [log.imported]
dependencies:
python:
requires-python: ">=3.12"
inherit: [pandas]
| Piece | Effect |
|---|---|
id in both files | The loader matches them; a mismatch fails the load with a clear error. |
@route.get | Registered under /api/v1/modules/my_module/top-activities, with auth and OpenAPI types handled. |
@job under @on_event | The precompute becomes a job the platform runs when a log first needs the module: it appears in the jobs UI and drives the page's progress state. |
ctx.cache | Results stored per (log_id, module_id), surviving restarts. |
requirements.event_log | The card is only offered on case-centric logs with those columns. |
Startup sequence#
Discovery — the folder is found by scanning
modules/*/manifest.yaml, or from amate.modulesentry point.Validation — the manifest is parsed and the dependency graph built; a cycle or a missing hard dependency logs a named error and drops that module plus its dependents, so one broken module never bricks the boot.
Materialisation — the dependency block is hashed; if it changed,
uv venv+uv pip installruns in the folder and the frontend is bundled into.dist/.Import and instantiate —
module.pyis imported under a private namespace with the module's ownsite-packages; your class is constructed exactly once per process.Binding — routes mounted, event handlers subscribed, job handlers registered, capabilities added to the registry.
Development loop#
| Task | How |
|---|---|
| Work on several modules | make lite MODULES=a,b; each reloads on its own. A folder created while the stack runs is picked up without a restart if its id is in MODULES (or MODULES is empty); otherwise restart with the id added. |
| Change a handler | Save; in ENV=dev the watchdog reloads that module in place. Earlier results go stale and recompute on the next open. |
| Change requirements or dependencies | Save; gating re-evaluates, and a changed dependency block triggers uv sync for that module. |
| Change the page | A Studio Save rewrites layout.json without restarting anything. A panel or widget is rebuilt by the bundler; refocus the tab. |
| Change platform code | uvicorn restarts the API, which drops an attached debugger; attach again. |
| List modules | make modules: id, version, name, runtime, UI (panel, layout, widgets, outputs). |
| Start from scratch | make reset deletes data/lite/ and nothing else. |
| Free a busy port | Lite never kills another process: DEBUGPY_PORT=5679 make lite PORT=8001 WEB_PORT=3001. |
Debugging#
| What | Where |
|---|---|
| Logs | The terminal running make lite (API, bundler, Next.js). LOG_LEVEL=debug make lite is more verbose. ctx.logger lines also reach the job log and the Logs tail on /modules/<id>. |
| Tracebacks | A load failure shows on /dev. A handler that raises in a worker logs modules.worker.handler_error with the full traceback, also sent to the job log and the module's live tail. |
| Breakpoints | VS Code Python Debugger extension, launch config Attach: MATE API (lite) on 127.0.0.1:5678. The API listens once at startup and never waits, so the stack runs the same without a debugger. DEBUGPY_PORT=0 turns it off. |
execution: worker jobs | Lite sets DEV_FORCE_THREAD=true, so they run in the API process and breakpoints bind. DEV_FORCE_THREAD=false make lite tests the real worker path. |
isolation: subprocess | DEBUGPY_WORKERS=true make lite; each worker logs MATE_DEBUGPY module=<id> pid=<pid> port=<port>. Attach with Attach: module worker (pick port). debugpy must be in the module's own venv while you debug. |
| Tests | Python: module tests runs pytest on the folder of the open file under the debugger. |
A job paused on a breakpoint keeps its wall clock running (JOB_EXECUTION_TIMEOUT_SECONDS, default 1800, 0 disables). JVM debugging, the full environment make lite sets, and a troubleshooting table are in docs/DEV_LITE.md.
Constraints#
- Do not import from
apps/api/*orapps/web/*— the SDK is the contract. - Do not construct log paths yourself; the ones from
ctxare ownership-checked. - Do not keep state on
self; the instance is shared and jobs run concurrently. - Do not call
asyncio.runinside a handler.