# nodus.functions

> Functions, FunctionCalls and `@app.cls` classes (resources.md §3.10, §3.11, ADR-047, ADR-110).

Source: https://nodus-platform-site.pages.dev/docs/reference/python/nodus-functions/
Build revision: 211ad9f836655b1c3a2668c4693e442471f28614

<!-- Generated by scripts/gen-reference.mjs from the SDK docstrings (griffe). Do not edit: run make gen. -->

Functions, FunctionCalls and `@app.cls` classes (resources.md §3.10, §3.11, ADR-047, ADR-110).

`.remote()`, `.spawn()` and `.map()` all create FunctionCall objects, the one fan-out mechanism of R3. Arguments are cloudpickled (`nodus._serialize`), results come back through a watch on the call, and a remote exception is re-raised as its own type when that type is importable here.

## `Cls`

```python
class Cls(fn: _Function) -> None
```

An `@app.cls` class: `Embedder()` gives an object whose `@nodus.method()`s have `.remote`, `.map`, `.spawn`.

### `Cls.from_name`

```python
from_name(app: str, name: str, project: str | None = None) -> _Cls
```

## `ClsObject`

```python
class ClsObject(fn: _Function) -> None
```

## `Function`

```python
class Function(*, raw: Callable[..., Any] | None = None, app: _App | None = None, options: FunctionOptions | None = None, user_cls: type | None = None, method: str | None = None, deployed: str | None = None, deployed_app: str | None = None, project: str | None = None, instance: _Obj | None = None) -> None
```

A Function defined with `@app.function`, a method of an `@app.cls` class, or a deployed one by name.

### `Function.estimate`

```python
estimate(*args: Any, **kwargs: Any) -> View
```

Dry-run one call: cold and warm start ETAs and the rate; `.etag` binds a reviewed launch.

### `Function.for_each`

```python
for_each(*iterables: Iterable[Any], ignore_exceptions: bool = False) -> None
```

Run the function over the inputs and discard the results.

### `Function.from_name`

```python
from_name(app: str, name: str, project: str | None = None) -> _Function
```

A deployed Function: `<app>-<name>` in the project (`Function.lookup` is an alias).

### `Function.get_raw_f`

```python
get_raw_f() -> Callable[..., Any]
```

The undecorated function (for a class method, the class).

### `Function.local`

```python
local(*args: Any, **kwargs: Any) -> Any
```

Run in this process, without Nodus.

### `Function.lookup`

### `Function.map`

```python
map(*iterables: Iterable[Any], kwargs: dict[str, Any] | None = None, order_outputs: bool = True, return_exceptions: bool = False) -> AsyncIterator[Any]
```

One FunctionCall per input, created in batches (≤1,000 calls, ≤8 MiB); results stream back as they finish.

### `Function.member`

### `Function.remote`

```python
remote(*args: Any, **kwargs: Any) -> Any
```

One FunctionCall: block until it finishes and return its result, or raise its exception.

### `Function.spawn`

```python
spawn(*args: Any, **kwargs: Any) -> _FunctionCall
```

Start one FunctionCall and return its handle without waiting.

### `Function.starmap`

```python
starmap(iterable: Iterable[Iterable[Any]], order_outputs: bool = True, return_exceptions: bool = False) -> AsyncIterator[Any]
```

## `FunctionCall`

```python
class FunctionCall(name: str, function: str | None = None, project: str | None = None) -> None
```

A handle on one FunctionCall: `.get(timeout=None)`, `.cancel()`, `.status()`, `.logs()`.

### `FunctionCall.cancel`

```python
cancel() -> None
```

### `FunctionCall.from_name`

```python
from_name(name: str, project: str | None = None) -> _FunctionCall
```

### `FunctionCall.function`

Type: `str | None`

### `FunctionCall.get`

```python
get(timeout: float | None = None) -> Any
```

Wait for the result; raises the remote exception, or `TimeoutError` after `timeout` seconds.

### `FunctionCall.logs`

```python
logs(follow: bool = False) -> AsyncIterator[str]
```

Log lines of the Function’s workers.

### `FunctionCall.name`

Type: `str`

### `FunctionCall.status`

```python
status() -> str | None
```

The call’s phase: `Queued`, `Running`, `Recovering`, `Succeeded`, `Failed`, `Cancelling` or `Cancelled`.

## `FunctionOptions`

```python
class FunctionOptions(name: str | None = None, gpu: Any = None, cpu: Any = None, memory: Any = None, ephemeral_disk: Any = None, image: Any = None, secrets: list[Any] = list(), volumes: dict[str, Any] = dict(), env: dict[str, str] | None = None, network: Any = None, timeout: Any = None, retries: Any = None, checkpoint: Any = None, interruptible: Any = None, region: Any = None, profile: Any = None, max_cost: Any = None, min_workers: int | None = None, max_workers: int | None = None, scaledown_window: Any = None, target_concurrency: int | None = None) -> None
```

The `@app.function` / `@app.cls` arguments, mapped to Function spec fields by `spec()`.

### `FunctionOptions.checkpoint`

Type: `Any`

### `FunctionOptions.cpu`

Type: `Any`

### `FunctionOptions.env`

Type: `dict[str, str] | None`

### `FunctionOptions.ephemeral_disk`

Type: `Any`

### `FunctionOptions.gpu`

Type: `Any`

### `FunctionOptions.image`

Type: `Any`

### `FunctionOptions.interruptible`

Type: `Any`

### `FunctionOptions.max_cost`

Type: `Any`

### `FunctionOptions.max_workers`

Type: `int | None`

### `FunctionOptions.memory`

Type: `Any`

### `FunctionOptions.min_workers`

Type: `int | None`

### `FunctionOptions.name`

Type: `str | None`

### `FunctionOptions.network`

Type: `Any`

### `FunctionOptions.profile`

Type: `Any`

### `FunctionOptions.region`

Type: `Any`

### `FunctionOptions.retries`

Type: `Any`

### `FunctionOptions.scaledown_window`

Type: `Any`

### `FunctionOptions.secrets`

Type: `list[Any]`

### `FunctionOptions.target_concurrency`

Type: `int | None`

### `FunctionOptions.timeout`

Type: `Any`

### `FunctionOptions.volumes`

Type: `dict[str, Any]`

## `clustered`

```python
clustered(size: int, launcher: str = 'Plain', network: str = 'Colocated', transport: str = 'Direct') -> Callable[[Callable[..., Any]], Callable[..., Any]]
```

Run each `.remote()` or `.spawn()` as one gang of `size` nodes; rank 0’s return value is the result (Beta).

Apply it below `@app.function`. `nodus.cluster.info()` gives each member its rank and the gang’s addresses.
