Running a function remotely

You can add a decorator to any Python function to run it remotely on Beam:
from beam import App, Runtime

app = App(name="my_app", runtime=Runtime())
def handler():
handlerYesThe handler function or entry point of the task to be executed. It should be a reference to the function that will process the task.
runtimeYesThe runtime environment for the task execution. Default is None.
outputsNoA list of of artifacts created during the task execution. Default is [].
**kwargsNoAdditional keyword arguments to pass to the handler.

Starting a run

Runs can be started with the beam run CLI command, by passing in a the name of a Python file and a function name.

beam run

The function logs will stream to stdout. Feel free to close your terminal window. The task will continue to run asynchronously, and you can view the logs and any outputs in the web dashboard.

user@MacBook % beam run
 i  Using cached image.
 ✓  App initialized.
 i  Uploading files...
Uploading 100% |██████████████████████| (1.7/1.7 kB, 13 kB/s)
 ✓  Container scheduled, logs will appear below.
Starting app...
Loading handler in ''...
Running task: 68d8c9a2-794b-4ac9-8661-489ed4d1c710
Task complete: 68d8c9a2-794b-4ac9-8661-489ed4d1c710, duration: 0.0024688243865966797s

By default, Beam will sync all the files in your working directory to the remote container. This allows you to use the files you have locally while developing. If you want to prevent some files from getting uploaded, you can create a .beamignore.

Passing function args

You can pass JSON arguments to your function, using the -d command in the CLI:

beam run -d '{"text": "foobar"}'

The arguments can be passed into your function as either explicit positional arguments, or keyword arguments.

Using positional arguments

def handler(text: str):
    # Prints foobar

Using keyword arguments

def handler(**kwargs):
    # Prints foobar

Task timeouts

You can set timeouts on tasks. Timeouts are set in seconds:

# Set a 24 hour timeout

# Disable timeouts completely

The default timeout is 3600 seconds, or 1 hour. You can set a timeout of -1 to disable the timeout.

Further Reading