On this page

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/
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.

  1. New — scaffold the folder. PANEL=1 also writes panel/index.tsx; the id must be snake_case and the folder must not exist. The scaffold passes validation as written: a manifest.yaml (in_process, one summary table output with a top param), a module.py (GET/summary plus a POST/recount job), a HOW_TO_USE.md, a layout.json with one card of each common kind, and tests/test_my_module.py.

    Terminal
    make install                  # once: uv + pnpm dependencies
    make new ID=my_module         # = uv run mate-module new my_module [--panel]
  2. 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 under data/lite/. Hard dependencies are added to MODULES automatically; leave it out to load every module.

    Terminal
    make lite MODULES=my_module   # API + bundler + web on :8000 / :3000; Ctrl-C stops all three
  3. Build the page — open Dev in the sidebar (/dev), then Open Studio. Save writes modules/my_module/layout.json — see The Studio. Edit module.py, manifest.yaml and HOW_TO_USE.md alongside. Saving module.py or manifest.yaml reloads the module; HOW_TO_USE.md is read fresh on every request.

  4. Test — in a second terminal, make test ID=my_module runs modules/my_module/tests — see Testing and publishing.

  5. Validate — make validate checks every module's manifest, guide and layout.json, and exits 1 on any problem.

  6. 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: run make docs and commit landing/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.

modules/my_module/HOW_TO_USE.md
# 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.

Terminal
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#

modules/my_module/module.py
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")
modules/my_module/manifest.yaml
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]
PieceEffect
id in both filesThe loader matches them; a mismatch fails the load with a clear error.
@route.getRegistered under /api/v1/modules/my_module/top-activities, with auth and OpenAPI types handled.
@job under @on_eventThe 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.cacheResults stored per (log_id, module_id), surviving restarts.
requirements.event_logThe card is only offered on case-centric logs with those columns.

Startup sequence#

  1. Discovery — the folder is found by scanning modules/*/manifest.yaml, or from a mate.modules entry point.

  2. 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.

  3. Materialisation — the dependency block is hashed; if it changed, uv venv + uv pip install runs in the folder and the frontend is bundled into .dist/.

  4. Import and instantiate — module.py is imported under a private namespace with the module's own site-packages; your class is constructed exactly once per process.

  5. Binding — routes mounted, event handlers subscribed, job handlers registered, capabilities added to the registry.

Development loop#

TaskHow
Work on several modulesmake 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 handlerSave; in ENV=dev the watchdog reloads that module in place. Earlier results go stale and recompute on the next open.
Change requirements or dependenciesSave; gating re-evaluates, and a changed dependency block triggers uv sync for that module.
Change the pageA Studio Save rewrites layout.json without restarting anything. A panel or widget is rebuilt by the bundler; refocus the tab.
Change platform codeuvicorn restarts the API, which drops an attached debugger; attach again.
List modulesmake modules: id, version, name, runtime, UI (panel, layout, widgets, outputs).
Start from scratchmake reset deletes data/lite/ and nothing else.
Free a busy portLite never kills another process: DEBUGPY_PORT=5679 make lite PORT=8001 WEB_PORT=3001.

Debugging#

WhatWhere
LogsThe 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>.
TracebacksA 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.
BreakpointsVS 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 jobsLite 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: subprocessDEBUGPY_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.
TestsPython: 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/* or apps/web/* — the SDK is the contract.
  • Do not construct log paths yourself; the ones from ctx are ownership-checked.
  • Do not keep state on self; the instance is shared and jobs run concurrently.
  • Do not call asyncio.run inside a handler.