{"id":4754,"library":"runloop-api-client","title":"Runloop API Client","description":"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.","status":"active","version":"1.18.1","language":"en","source_language":"en","source_url":"https://github.com/runloopai/api-client-python","tags":["API client","MLOps","AI","DevOps","cloud development"],"install":[{"cmd":"pip install runloop_api_client","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Requires Python 3.9 or higher for compatibility.","package":"python","optional":false},{"reason":"Optional dependency for improved concurrency performance with the asynchronous client.","package":"aiohttp","optional":true}],"imports":[{"note":"Use this for the higher-level, object-oriented synchronous API client.","symbol":"RunloopSDK","correct":"from runloop_api_client import RunloopSDK"},{"note":"Use this for the higher-level, object-oriented asynchronous API client, recommended for performance.","symbol":"AsyncRunloopSDK","correct":"from runloop_api_client import AsyncRunloopSDK"},{"note":"Use this for direct access to the lower-level REST API client. The SDK interfaces (RunloopSDK/AsyncRunloopSDK) are generally preferred.","symbol":"Runloop","correct":"from runloop_api_client import Runloop"}],"quickstart":{"code":"import asyncio\nimport os\nfrom runloop_api_client import AsyncRunloopSDK\n\nasync def run_example():\n    # API Key is auto-loaded from \"RUNLOOP_API_KEY\" env var by default.\n    # Ensure RUNLOOP_API_KEY is set in your environment (e.g., export RUNLOOP_API_KEY=\"your_api_key_here\")\n    # or pass it explicitly: AsyncRunloopSDK(bearer_token=\"your_api_key_here\")\n    runloop = AsyncRunloopSDK(bearer_token=os.environ.get('RUNLOOP_API_KEY', ''))\n\n    devbox = None # Initialize devbox to None for finally block\n    try:\n        # Create a devbox and wait for it to be ready\n        devbox = await runloop.devbox.create()\n        print(f'Created Runloop Devbox: {devbox.id}')\n\n        # Execute a command and wait for it to complete\n        result = await devbox.cmd.exec(command=\"echo 'Hello from Runloop!!'\")\n        print(f'Output: {await result.stdout()}')\n        print(f'Exit code: {result.exit_code}')\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n    finally:\n        if devbox:\n            print(f'Shutting down Devbox: {devbox.id}')\n            await devbox.shutdown()\n\nif __name__ == \"__main__\":\n    # Ensure the RUNLOOP_API_KEY environment variable is set.\n    if not os.environ.get('RUNLOOP_API_KEY'):\n        print(\"Warning: RUNLOOP_API_KEY environment variable is not set.\")\n        print(\"Please set it (e.g., export RUNLOOP_API_KEY='your_api_key_here') before running.\")\n    asyncio.run(run_example())\n","lang":"python","description":"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."},"warnings":[{"fix":"Review the latest documentation for blueprint management for alternative or updated methods. It is listed as deprecated in API specs.","message":"The `blueprints.preview()` method has been deprecated.","severity":"deprecated","affected_versions":">=1.16.0"},{"fix":"Update imports from `Runloop` to `RunloopSDK` or `AsyncRunloopSDK` and adjust method calls to use the `sdk.api` property for direct REST API access or the object-oriented interfaces (e.g., `sdk.devbox`).","message":"Migration from an older 'API Client' to the current `RunloopSDK` structure may require updating import paths and method calls. For instance, `runloop.secrets` has moved to `runloopSDK.api.secrets`.","severity":"breaking","affected_versions":"Potentially older versions to current `RunloopSDK` based versions."},{"fix":"Always ensure the `RUNLOOP_API_KEY` environment variable is set before initializing the client, or explicitly pass `bearer_token` during client instantiation: `RunloopSDK(bearer_token=\"your_key\")`.","message":"Authentication primarily relies on the `RUNLOOP_API_KEY` environment variable. If not set, the client may fail to authenticate or you'll need to pass the `bearer_token` explicitly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always call `await devbox.shutdown()` or use a `with` statement with `runloop.devbox.create()` for proper resource cleanup.","message":"Devboxes are persistent resources. Failing to explicitly shut down a `Devbox` using `await devbox.shutdown()` (or using a context manager with `with runloop.devbox.create(...)`) can lead to lingering resources and unexpected costs.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}