How Beam Works

Beam is a new kind of cloud provider that makes the experience of using the cloud feel almost the same as using your local machine.

It’s powered by an open-source container orchestrator that launches containers in less than 1 second.

Functions

You can run functions on the cloud, either once, or on a schedule. Learn more about Functions.

Functions

One-off Python functions, like training runs, scraping, or batch jobs.

from beam import function

@function()
def handler():
    return {}

if __name__ == "__main__":
    # Runs locally
    handler.local()
    # Runs on the cloud
    handler.remote()

Scheduled Jobs

Functions that run based on a schedule you specify.

from beam import schedule

@schedule(when="every 1d")
def handler():
    return {}

if __name__ == "__main__":
    # Runs locally
    handler.local()
    # Runs on the cloud
    handler.remote()

Run Your Function

You’ll run your functions like a normal Python function: python app.py. Even though it feels like the code is running locally, it’s running on a container in the cloud.

Endpoints

You can also deploy synchronous and asynchronous web endpoints. Learn more about Endpoints and Task Queues.

Endpoints

Synchronous REST API endpoints, for tasks that run in 60s or less.

from beam import endpoint

@endpoint(name="quickstart")
def handler():
  return {}

Task Queues

Asynchronous REST API endpoints, for heavier tasks that take a long time to run.

from beam import task_queue

@task_queue(name="quickstart")
def handler():
  print(48393 * 39383)

Testing Your Code

Beam provides a temporary cloud environment to test your code.


These environments hot-reload with your code changes. You can test your workflow end-to-end before deploying to production.

beam serve app.py:handler

Deploying to Production

When you’re ready to deploy a persistent endpoint, you’ll use beam deploy:

beam deploy app.py:handler

Web Services

You can also bring your own container and host web services, like Jupyter Notebooks, Node.js apps, and much more. Learn more about Pods.

Pods

Run any container behind an SSL-backed REST API.

from beam import Pod

pod = Pod(
  name="my-pod",
  cpu=2,
  memory="1Gi",
  ports=[8000],
  entrypoint=["python", "-m", "http.server", "8000"],
)

# Run the container as an API
pod.deploy()