---
title: Functions
slug: functions
summary: Write a Function, expose it as an action, HTTP routes or a sync, run it, and publish it.
---

# Functions

A Function is Python code at `functions/<slug>/function.py` in a Workspace.
LimiLake runs it on its servers when someone calls it, when a schedule fires,
or when an App or an Agent uses it.

## Anatomy

```python
import limilake
from limilake import logger

fn = limilake.function(
    id="123e4567-e89b-42d3-a456-426614174000",  # Contract v2 durable identity
    name="daily-report",
    description="Build the daily invoice report",
    access="private",
    run_as="caller",
)


@fn.action
def run(payload: dict[str, str]) -> dict[str, str]:
    rows = limilake.lake.read_table("bronze.invoices")
    logger.info(f"read {len(rows)} rows")
    return {"status": "ok", "requested_by": payload["requested_by"]}
```

`limilake add function` follows the Workspace Contract and writes this file
with a generated `id`. Keep the `id` when you edit or move the Function. Each
file declares exactly one `limilake.function(...)`. `description` tells people
and agents what the Function does.

## What a Function can expose

A Function exposes one or more of these. Add `schedule=` to run its action or
sync on a cron schedule; see [Schedules](./schedules.md).

**An action** is one call with an input object and a result:

```python
@fn.action
def greet(payload: dict[str, str]) -> dict[str, str]:
    return {"message": f"Hello {payload['name']}"}
```

**HTTP routes** answer web requests. The decorators work like FastAPI's, so
path, query and body parameters and Pydantic models work as usual. A published
App calls them, and so do other systems:

```python
@fn.get("/orders")
def list_orders() -> list[dict[str, object]]:
    return limilake.lake.read_table("silver.orders")
```

**A sync** loads data into a Lakehouse incrementally. This one copies rows
that changed in `bronze.orders` since the last run into `silver.orders`:

```python
@fn.sync
def orders_to_silver() -> None:
    changed = limilake.sync.source_changes("bronze.orders")
    limilake.sync.write(changed, to="silver.orders", key=["id"], sources=["bronze.orders"])
```

To reach an external system, call it through `limilake.connections`; see
[Connections](./connections.md). To start an AI agent from a Function, see
[Agents](./agents.md).

## Running

- **Live (default):** `limilake function invoke <function>` runs it server-side in a real sandbox: true production parity.
- **Standalone local:** `limilake function invoke <function> --local` and `limilake function serve` run the function in your workspace venv against live data and egress, for breakpoints and hot reload. These commands currently resolve the CLI session before starting the runtime.
- **Workspace dev loop:** `limilake dev` runs deliberate local actions through the Workspace runtime without requiring a session for pure code or logging. Governed capabilities bootstrap only when used; HTTP Functions still require the CLI session because their long-lived serve runtime starts eagerly.

Pass the input as JSON with `--input '{"requested_by":"me"}'`.

In every mode, governed data, AI, and egress calls hit the live platform and use
live server authorization. Only pure deliberate actions in the Workspace dev
loop can complete without contacting it.

## Publish

There is no separate Function deployment. Pushing the complete Workspace
Revision to `main` publishes its source. Once that revision is indexed, valid
Function routes and code schedules become current from that accepted `main`.

Create the contract-shaped Function in the normal Workspace checkout, edit its
fixed entrypoint, and publish the complete revision with Git:

```bash
limilake add function daily-report
# edit functions/daily-report/function.py
git add -- functions/daily-report/function.py
git commit -m "Add daily report Function"
git push origin HEAD:main
limilake function list                       # see Functions indexed from main
limilake publication show
limilake function show functions/daily-report/function.py --workspace my-ws
limilake function logs functions/daily-report/function.py --workspace my-ws
```

`limilake publication show` inspects the asynchronous Build and App-artifact
activation. Function commands do not wait for App activation; they resolve the
latest indexed `main` Function and its Runs.

## Limits and gotchas

- A handler takes no parameter, or one required `dict[str, T]` parameter that
  receives the whole input object. Fields are not mapped onto Python
  parameters by name, and defaults are invalid.
- A Function has at most one `@fn.action` and one `@fn.sync`. It can have any
  number of HTTP routes.
- Use `limilake.lake`, `limilake.sync` and the other governed helpers inside
  the handler, not at module level.
- Your code never holds a provider's secret. Connections add credentials on
  the server.
- A run times out after 30 minutes unless you set `timeout=` (1 minute to 24
  hours). A Function handles `concurrency_limit` requests at a time (default
  4, at most 100); past that, a call gets `429`, after a wait of up to 30
  seconds when it comes from a published App. See
  [Sandboxes](./sandboxes.md).
- `limilake dev` does not run a sync. Run it on LimiLake with
  `limilake function invoke`.

## Next steps

- [Functions reference](./functions-reference.md): access modes, who is
  calling, AI decisions and model roles, share links.
- [Schedules](./schedules.md): run an action or a sync on a schedule.
- [Apps](./apps.md): call a Function's routes from a React App.
- [Sandboxes](./sandboxes.md): where runs happen, and their limits.
