@@ -77,6 +77,7 @@ print(obj.download_as_text())
7777import asyncio
7878from runloop_api_client import AsyncRunloopSDK
7979
80+
8081async def main ():
8182 runloop = AsyncRunloopSDK()
8283 async with await runloop.devbox.create(name = " async-devbox" ) as devbox:
@@ -88,6 +89,7 @@ async def main():
8889
8990 await devbox.cmd.exec(" ls" , stdout = capture)
9091
92+
9193asyncio.run(main())
9294```
9395
@@ -194,7 +196,7 @@ print("Devbox ID:", execution.devbox_id)
194196# Poll for current state
195197state = execution.get_state()
196198print (" Status:" , state.status) # "running", "completed", etc.
197- print (" Exit code:" , state.exit_status) # only set when execution has completed
199+ print (" Exit code:" , state.exit_status) # only set when execution has completed
198200
199201# Wait for completion and get results
200202result = execution.result()
@@ -229,7 +231,7 @@ result = execution.result()
229231# Access execution results
230232print (" Exit code:" , result.exit_code)
231233print (" Success:" , result.success) # True if exit code is 0
232- print (" Failed:" , result.failed) # True if exit code is non-zero
234+ print (" Failed:" , result.failed) # True if exit code is non-zero
233235
234236# Get output streams
235237stdout = result.stdout()
@@ -261,6 +263,7 @@ Pass callbacks into `cmd.exec` / `cmd.exec_async` to process logs in real time:
261263def handle_output (line : str ) -> None :
262264 print (" LOG:" , line)
263265
266+
264267result = devbox.cmd.exec(
265268 " python train.py" ,
266269 stdout = handle_output,
@@ -278,6 +281,7 @@ def capture(line: str) -> None:
278281 # Use thread-safe data structures if needed
279282 log_queue.put_nowait(line)
280283
284+
281285await devbox.cmd.exec(
282286 " tail -f /var/log/app.log" ,
283287 stdout = capture,
@@ -299,6 +303,7 @@ print(content)
299303
300304# Upload files
301305from pathlib import Path
306+
302307devbox.file.upload(
303308 path = " /home/user/upload.txt" ,
304309 file = Path(" local_file.txt" ),
@@ -535,6 +540,7 @@ storage_object.complete()
535540
536541# Upload from file
537542from pathlib import Path
543+
538544uploaded = runloop.storage_object.upload_from_file(
539545 Path(" /path/to/file.txt" ),
540546 name = " my-file.txt" ,
@@ -584,7 +590,7 @@ obj = runloop.storage_object.create(
584590 name = " data.bin" ,
585591 content_type = " binary" ,
586592)
587- obj.upload_content(b " \xDE\xAD\xBE\xEF " )
593+ obj.upload_content(b " \xde\xad\xbe\xef " )
588594obj.complete()
589595```
590596
@@ -731,28 +737,30 @@ The async SDK has the same interface as the synchronous version, but all I/O ope
731737import asyncio
732738from runloop_api_client import AsyncRunloopSDK
733739
740+
734741async def main ():
735742 runloop = AsyncRunloopSDK()
736-
743+
737744 # All the same operations, but with await
738745 async with await runloop.devbox.create(name = " async-devbox" ) as devbox:
739746 result = await devbox.cmd.exec(" pwd" )
740747 print (await result.stdout())
741-
748+
742749 # Streaming (note: callbacks must be synchronous)
743750 def capture (line : str ) -> None :
744751 print (" >>" , line)
745-
752+
746753 await devbox.cmd.exec(" ls" , stdout = capture)
747-
754+
748755 # Async file operations
749756 await devbox.file.write(path = " /tmp/test.txt" , contents = " Hello" )
750757 content = await devbox.file.read(path = " /tmp/test.txt" )
751-
758+
752759 # Async network operations
753760 tunnel = await devbox.net.create_tunnel(port = 8080 )
754761 print (" Tunnel URL:" , tunnel.url)
755762
763+
756764asyncio.run(main())
757765```
758766
@@ -768,15 +776,15 @@ devbox = runloop.devbox.create(
768776 name = " my-devbox" ,
769777 polling_config = PollingConfig(
770778 timeout_seconds = 300.0 , # Wait up to 5 minutes
771- interval_seconds = 2.0 , # Poll every 2 seconds
779+ interval_seconds = 2.0 , # Poll every 2 seconds
772780 ),
773781)
774782
775783# Wait for snapshot completion with custom polling
776784snapshot.await_completed(
777785 polling_config = PollingConfig(
778786 timeout_seconds = 600.0 , # Wait up to 10 minutes
779- interval_seconds = 5.0 , # Poll every 5 seconds
787+ interval_seconds = 5.0 , # Poll every 5 seconds
780788 ),
781789)
782790```
0 commit comments