Hello, world!¶
The basics: run functions locally, remotely, and in parallel.
The code¶
import sys
import openmodal
app = openmodal.App("example-hello-world")
@app.function()
def f(i):
if i % 2 == 0:
print("hello", i)
else:
print("world", i, file=sys.stderr)
return i * i
@app.local_entrypoint()
def main():
print(f.local(1000)) # runs on your machine
print(f.remote(1000)) # runs in a container
total = 0
for ret in f.map(range(200)): # 200 calls in parallel
total += ret
print(total)
Run it¶
What happened?¶
f.local(1000)ran on your machine — returned1000000f.remote(1000)ran inside a container (Docker or cloud VM) — same resultf.map(range(200))sent 200 calls to the container in parallel
The container was automatically cleaned up when the script finished.