-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhello_world.py
More file actions
65 lines (48 loc) · 1.67 KB
/
hello_world.py
File metadata and controls
65 lines (48 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
"""
Hello World Example - The Simplest Grainchain Usage
This example demonstrates the absolute simplest way to use grainchain.
Perfect for getting started in just a few lines of code!
"""
import asyncio
from grainchain import create_local_sandbox
async def hello_world():
"""The simplest possible grainchain example."""
print("🏜️ Grainchain Hello World")
print("=" * 30)
# Create and use a sandbox in just 3 lines!
sandbox = create_local_sandbox()
async with sandbox:
result = await sandbox.execute("echo 'Hello, Grainchain!'")
print(f"Output: {result.stdout.strip()}")
async def hello_python():
"""Simple Python execution example."""
print("\n🐍 Python Hello World")
print("=" * 30)
sandbox = create_local_sandbox()
async with sandbox:
result = await sandbox.execute("python3 -c 'print(\"Hello from Python!\")'")
print(f"Output: {result.stdout.strip()}")
async def hello_file():
"""Simple file operations example."""
print("\n📁 File Operations Hello World")
print("=" * 30)
sandbox = create_local_sandbox()
async with sandbox:
# Create a simple Python script
script = """
print("Hello from a file!")
print(f"2 + 2 = {2 + 2}")
"""
# Upload and execute
await sandbox.upload_file("hello.py", script)
result = await sandbox.execute("python3 hello.py")
print("Output:")
print(result.stdout.strip())
if __name__ == "__main__":
async def main():
await hello_world()
await hello_python()
await hello_file()
print("\n✅ All hello world examples completed!")
asyncio.run(main())