Arguments
The previous “Hello, World!” example used a function that took no arguments. Here’s how to pass arguments to your functions using Hyperscript with the Convergence backend.
Here, we’ll modify the hello_world function to accept a name as an argument and return a personalized greeting.
from hyperscript import Hyperscriptfrom hyperscript.convergence import Convergenceimport os
# Define the function we want run in the clouddef hello_world(name): return f"Hello, {name}!"
async def main(): # Set up Convergence as our backend convergence = Convergence(api_key=os.getenv("CONVERGENCE_API_KEY"))
# Initialize Hyperscript with Convergence's storage and event systems async with Hyperscript( storage=convergence.storage, events=convergence.events ) as hs: # Run the hello_world function in the cloud task = await hs.run(fn=hello_world, args=["Cammy"], executor=convergence.executor)
# Retrieve and print the result async for result in task.results(): print(f"Got result: {result}") # Should print "Got result: Hello, Cammy!"
# Hyperscript leverages asyncio, so we need to run our main function in an event loopif __name__ == "__main__": import asyncio
asyncio.run(main())