Skip to content

Shell

from hyperscript import Hyperscript
from hyperscript.convergence import Convergence
def shell_script(name):
from hyperscript.Shell import Shell
from hyperscript.File import File
shell = Shell(f"""
echo "Hello, {name}!" > output.txt
""")
for stdout in shell.execute():
print(stdout)
return File("output.txt") # Return the output file
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:
task = await hs.run(fn=shell_script,
args=["Cammy"],
executor=convergence.executor
)
# Retrieve and print the result
async for file in task.files():
print(f"Got file: {file.name}")
# Hyperscript leverages asyncio, so we need to run our main function in an event loop
if __name__ == "__main__":
import asyncio
asyncio.run(main())