Python modules

Write shared Python once and call it from every action, handler and job in your organization.

A Python module is named code that Octocom loads into every Python execution in your organization. You write a function once and call it anywhere, with no import. For example, a monday_request function that calls Monday's API with your stored key can serve every action, event handler and recurring job that works with your boards.

Modules are available in custom actions, condition providers, event handlers, recurring jobs, prompt sections, HTTP endpoints and sidebar widgets. Use one for anything you would otherwise paste into several places: an API wrapper, shared formatting, a lookup table, the constants your team keeps re-typing. When the shared piece is data that changes at runtime rather than code, use the organization store instead. For credentials, use secrets.

Modules live under Settings -> Advanced -> Modules.

Write a module

Define plain top-level functions and constants:

TEAM_QUEUES = {
    "web": "Web Team",
    "warehouse": "Warehouse",
}


def team_label(team_key):
    """Human name for a team key."""
    return TEAM_QUEUES.get(team_key, team_key)


def monday_request(query):
    """Call Monday's GraphQL API with the org's stored credentials."""
    response = requests.post(
        "https://api.monday.com/v2",
        headers={"Authorization": get_secret("MONDAY_API_KEY")},
        json={"query": query},
        timeout=30,
    )
    response.raise_for_status()
    return response.json()

Then call them from anywhere:

def execute_action(context):
    boards = monday_request("{ boards(limit: 5) { id name } }")
    return {"team": team_label("web"), "boards": boards}

How modules are loaded

  • Module contents are injected, not imported. Active modules are placed before your code in every execution. The module's name identifies it in the dashboard; it does not namespace the functions.
  • Modules load after the built-in helpers, so a module can call every built-in helper, and a function you define with the same name as a built-in replaces it.
  • Inactive modules are not loaded. Turn a module off to take it out of circulation without deleting it.
  • Product sync parsers don't load modules. A parser runs in its own runtime with its own helpers.

A syntax error in an active module breaks every Python execution in your organization: actions, condition providers, prompt sections, event handlers, recurring jobs, HTTP endpoints and sidebar widgets alike. Test new code before you save or activate a module (see Best practices).

Where modules apply

Manage modules with Copilot, MCP or REST

InterfaceOperations
MCPlist_python_modules, get_python_module, create_python_module, update_python_module, archive_python_module
RESTGET /rest/v1/python-modules, GET /rest/v1/python-modules/:id, POST /rest/v1/python-modules, PATCH /rest/v1/python-modules/:id

Writing a module needs the automations:write scope, like any setting that holds code.

Best practices

  • Prefix every name. Use a short prefix per module (crm_, billing_) so two modules, or a module and a built-in helper, never collide by accident.
  • Only define things. Keep modules to function and constant definitions. Make no API calls and no slow work at import time: that code runs before every execution in the organization.
  • Keep secrets out. Read credentials with get_secret inside a function, never as a module-level constant.
  • Test before saving. A saved, active module is part of every execution from then on, and an inactive one is not loaded at all. Paste the new code into run_python together with a small execute_action that calls it, check the result, then save or activate the module.

On this page