Runloop API Client

1.18.1 · active · verified Sun Apr 12

The `runloop-api-client` is the official Python library for interacting with the Runloop API, providing convenient access to its REST API from any Python 3.9+ application. It offers both synchronous (`RunloopSDK`) and asynchronous (`AsyncRunloopSDK`) clients, enabling programmatic management of Devboxes, Blueprints, Snapshots, and Storage Objects. The library is actively maintained with frequent releases, adding new features and bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `AsyncRunloopSDK` client, create a Devbox, execute a command within it, and then properly shut down the Devbox. Ensure your `RUNLOOP_API_KEY` is set as an environment variable for authentication.

import asyncio
import os
from runloop_api_client import AsyncRunloopSDK

async def run_example():
    # API Key is auto-loaded from "RUNLOOP_API_KEY" env var by default.
    # Ensure RUNLOOP_API_KEY is set in your environment (e.g., export RUNLOOP_API_KEY="your_api_key_here")
    # or pass it explicitly: AsyncRunloopSDK(bearer_token="your_api_key_here")
    runloop = AsyncRunloopSDK(bearer_token=os.environ.get('RUNLOOP_API_KEY', ''))

    devbox = None # Initialize devbox to None for finally block
    try:
        # Create a devbox and wait for it to be ready
        devbox = await runloop.devbox.create()
        print(f'Created Runloop Devbox: {devbox.id}')

        # Execute a command and wait for it to complete
        result = await devbox.cmd.exec(command="echo 'Hello from Runloop!!'")
        print(f'Output: {await result.stdout()}')
        print(f'Exit code: {result.exit_code}')

    except Exception as e:
        print(f"An error occurred: {e}")
    finally:
        if devbox:
            print(f'Shutting down Devbox: {devbox.id}')
            await devbox.shutdown()

if __name__ == "__main__":
    # Ensure the RUNLOOP_API_KEY environment variable is set.
    if not os.environ.get('RUNLOOP_API_KEY'):
        print("Warning: RUNLOOP_API_KEY environment variable is not set.")
        print("Please set it (e.g., export RUNLOOP_API_KEY='your_api_key_here') before running.")
    asyncio.run(run_example())

view raw JSON →