# Chalk DataFrames Reference: RemoteFunction
source: https://docs.chalk.ai/dataframe-docs#section-remotefunction

A deployed remote function.

Returned by `function`. The calling convention mirrors Python:

- `def f() -> int`: `result = fn(args)`
- `async def f() -> int`: `result = await fn(args)`
- `def f() -> Iterator`: `for x in fn(args): ...`
- `async def f() -> AsyncIterator`: `async for x in fn(args): ...`

Use `defer` for deferred execution via the function queue.

## `RemoteFunction`
source: https://docs.chalk.ai/dataframe-docs#RemoteFunction

Class

A deployed remote function.

Supports both direct calls and deferred calls.

Calling Convention:

- Scalar functions: `result = fn(args)` in sync code or `result = await fn(args)` in async code.
- `def f() -> Iterator[int]`: `for x in fn(args): ...`
- `async def f() -> AsyncIterator[int]`: `async for x in fn(args): ...`

All function types also support deferred execution via the function queue:

- `handle = fn.defer(args)`
- `result = handle.get()` or `for x in handle.stream(): ...`

### `RemoteFunction.__call__(args)`
source: https://docs.chalk.ai/dataframe-docs#RemoteFunction.__call__

Call the function directly through the scaling group via Velox.

Returns the appropriate type based on the function's signature:

- Scalar function in sync code: returns the value
- Scalar function in async code: returns a coroutine
- Sync generator: returns an iterator
- Async generator: returns an async iterator

### `RemoteFunction.defer(args)`
source: https://docs.chalk.ai/dataframe-docs#RemoteFunction.defer

Enqueue the call via the function queue and return a handle immediately.

### `RemoteFunction.purge()`
source: https://docs.chalk.ai/dataframe-docs#RemoteFunction.purge

Drop all pending items from this function's Redis queue.

Already-popped (in-flight) calls continue to completion; only items still pending in the queue are removed. Returns the number of items that were dropped.

**Raises**

- `RuntimeError`: When the function was constructed without a queue client.
