runloop-api-client 1.21.0


pip install runloop-api-client

  Latest version

Released: May 13, 2026


Meta
Author: Runloop
Requires Python: >=3.9

Classifiers

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Operating System
  • MacOS
  • Microsoft :: Windows
  • OS Independent
  • POSIX
  • POSIX :: Linux

Programming Language
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14

Topic
  • Software Development :: Libraries :: Python Modules

Typing
  • Typed

Runloop Python API library

PyPI version

The Runloop Python library provides convenient access to the Runloop REST API from any Python 3.9+ application. The library includes type definitions for all request params and response fields, and offers both synchronous and asynchronous clients powered by httpx.

It is generated with Stainless.

Documentation

The REST API documentation can be found on runloop.ai. The full API of this library can be found in api.md.

Installation

# install from PyPI
pip install runloop_api_client

Usage

The full API of this library can be found in api.md.

Object-Oriented SDK

For a higher-level, Pythonic interface, check out the new RunloopSDK which layers an object-oriented API on top of the generated client (including synchronous and asynchronous variants).

from runloop_api_client import RunloopSDK

runloop = RunloopSDK()  # Uses RUNLOOP_API_KEY environment variable by default

# Create a devbox and execute commands with a clean, object-oriented interface
with runloop.devbox.create(name="my-devbox") as devbox:
    result = devbox.cmd.exec("echo 'Hello from Runloop!'")
    print(result.stdout())

See the SDK documentation for complete examples and API reference.

REST API Client

Alternatively, you can use the generated REST API client directly:

import os
from runloop_api_client import Runloop

client = Runloop(
    bearer_token=os.environ.get("RUNLOOP_API_KEY"),  # This is the default and can be omitted
)

devbox_view = client.devboxes.create()
print(devbox_view.id)

While you can provide a bearer_token keyword argument, we recommend using python-dotenv to add RUNLOOP_API_KEY="My Bearer Token" to your .env file so that your Bearer Token is not stored in source control.

Async usage

Simply import AsyncRunloop instead of Runloop and use await with each API call:

import os
import asyncio
from runloop_api_client import AsyncRunloop

client = AsyncRunloop(
    bearer_token=os.environ.get("RUNLOOP_API_KEY"),  # This is the default and can be omitted
)


async def main() -> None:
    devbox_view = await client.devboxes.create()
    print(devbox_view.id)


asyncio.run(main())

Functionality between the synchronous and asynchronous clients is otherwise identical.

Examples

Workflow-oriented runnable examples are documented in EXAMPLES.md.

EXAMPLES.md is generated from metadata in examples/*.py and should not be edited manually. Regenerate it with:

uv run python scripts/generate_examples_md.py

Agent Guidance

Detailed agent-specific instructions for developing using this package live in llms.txt. Consolidated recipes for frequent tasks are in EXAMPLES.md.

After completing any modifications to this project, ensure llms.txt and README.md are kept in sync.

With aiohttp

By default, the async client uses httpx for HTTP requests. However, for improved concurrency performance you may also use aiohttp as the HTTP backend.

You can enable this by installing aiohttp:

# install from PyPI
pip install runloop_api_client[aiohttp]

Then you can enable it by instantiating the client with http_client=DefaultAioHttpClient():

import os
import asyncio
from runloop_api_client import DefaultAioHttpClient
from runloop_api_client import AsyncRunloop


async def main() -> None:
    async with AsyncRunloop(
        bearer_token=os.environ.get("RUNLOOP_API_KEY"),  # This is the default and can be omitted
        http_client=DefaultAioHttpClient(),
    ) as client:
        devbox_view = await client.devboxes.create()
        print(devbox_view.id)


asyncio.run(main())

Using types

Nested request parameters are TypedDicts. Responses are Pydantic models which also provide helper methods for things like:

  • Serializing back into JSON, model.to_json()
  • Converting to a dictionary, model.to_dict()

Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set python.analysis.typeCheckingMode to basic.

Pagination

List methods in the Runloop API are paginated.

This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:

from runloop_api_client import Runloop

client = Runloop()

all_devboxes = []
# Automatically fetches more pages as needed.
for devbox in client.devboxes.list():
    # Do something with devbox here
    all_devboxes.append(devbox)
print(all_devboxes)

Or, asynchronously:

import asyncio
from runloop_api_client import AsyncRunloop

client = AsyncRunloop()


async def main() -> None:
    all_devboxes = []
    # Iterate through items across all pages, issuing requests as needed.
    async for devbox in client.devboxes.list():
        all_devboxes.append(devbox)
    print(all_devboxes)


asyncio.run(main())

Alternatively, you can use the .has_next_page(), .next_page_info(), or .get_next_page() methods for more granular control working with pages:

first_page = await client.devboxes.list()
if first_page.has_next_page():
    print(f"will fetch next page using these details: {first_page.next_page_info()}")
    next_page = await first_page.get_next_page()
    print(f"number of items we just fetched: {len(next_page.devboxes)}")

# Remove `await` for non-async usage.

Or just work directly with the returned data:

first_page = await client.devboxes.list()

print(f"next page cursor: {first_page.starting_after}")  # => "next page cursor: ..."
for devbox in first_page.devboxes:
    print(devbox.id)

# Remove `await` for non-async usage.

Nested params

Nested parameters are dictionaries, typed using TypedDict, for example:

from runloop_api_client import Runloop

client = Runloop()

devbox_view = client.devboxes.create(
    launch_parameters={},
)
print(devbox_view.launch_parameters)

File uploads

Request parameters that correspond to file uploads can be passed as bytes, or a PathLike instance or a tuple of (filename, contents, media type).

from pathlib import Path
from runloop_api_client import Runloop

client = Runloop()

client.devboxes.upload_file(
    id="id",
    path="path",
    file=Path("/path/to/file"),
)

The async client uses the exact same interface. If you pass a PathLike instance, the file contents will be read asynchronously automatically.

Handling errors

When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of runloop_api_client.APIConnectionError is raised.

When the API returns a non-success status code (that is, 4xx or 5xx response), a subclass of runloop_api_client.APIStatusError is raised, containing status_code and response properties.

All errors inherit from runloop_api_client.APIError.

import runloop_api_client
from runloop_api_client import Runloop

client = Runloop()

try:
    client.devboxes.create()
except runloop_api_client.APIConnectionError as e:
    print("The server could not be reached")
    print(e.__cause__)  # an underlying Exception, likely raised within httpx.
except runloop_api_client.RateLimitError as e:
    print("A 429 status code was received; we should back off a bit.")
except runloop_api_client.APIStatusError as e:
    print("Another non-200-range status code was received")
    print(e.status_code)
    print(e.response)

Error codes are as follows:

Status Code Error Type
400 BadRequestError
401 AuthenticationError
403 PermissionDeniedError
404 NotFoundError
422 UnprocessableEntityError
429 RateLimitError
>=500 InternalServerError
N/A APIConnectionError

Retries

Certain errors are automatically retried 5 times by default, with a short exponential backoff. Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors are all retried by default for GET requests. For POST requests, only 429 errors will be retried.

You can use the max_retries option to configure or disable retry settings:

from runloop_api_client import Runloop

# Configure the default for all requests:
client = Runloop(
    # default is 5
    max_retries=0,
)

# Or, configure per-request:
client.with_options(max_retries=10).devboxes.create()

Timeouts

By default requests time out after 30 seconds. You can configure this with a timeout option, which accepts a float or an httpx.Timeout object:

from runloop_api_client import Runloop

# Configure the default for all requests:
client = Runloop(
    # 20 seconds (default is 30 seconds)
    timeout=20.0,
)

# More granular control:
client = Runloop(
    timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
)

# Override per-request:
client.with_options(timeout=5.0).devboxes.create()

On timeout, an APITimeoutError is thrown.

Note that requests that time out are retried twice by default.

Advanced

Logging

We use the standard library logging module.

You can enable logging by setting the environment variable RUNLOOP_LOG to info.

$ export RUNLOOP_LOG=info

Or to debug for more verbose logging.

How to tell whether None means null or missing

In an API response, a field may be explicitly null, or missing entirely; in either case, its value is None in this library. You can differentiate the two cases with .model_fields_set:

if response.my_field is None:
  if 'my_field' not in response.model_fields_set:
    print('Got json like {}, without a "my_field" key present at all.')
  else:
    print('Got json like {"my_field": null}.')

Accessing raw response data (e.g. headers)

The "raw" Response object can be accessed by prefixing .with_raw_response. to any HTTP method call, e.g.,

from runloop_api_client import Runloop

client = Runloop()
response = client.devboxes.with_raw_response.create()
print(response.headers.get('X-My-Header'))

devbox = response.parse()  # get the object that `devboxes.create()` would have returned
print(devbox.id)

These methods return an APIResponse object.

The async client returns an AsyncAPIResponse with the same structure, the only difference being awaitable methods for reading the response content.

.with_streaming_response

The above interface eagerly reads the full response body when you make the request, which may not always be what you want.

To stream the response body, use .with_streaming_response instead, which requires a context manager and only reads the response body once you call .read(), .text(), .json(), .iter_bytes(), .iter_text(), .iter_lines() or .parse(). In the async client, these are async methods.

with client.devboxes.with_streaming_response.create() as response:
    print(response.headers.get("X-My-Header"))

    for line in response.iter_lines():
        print(line)

The context manager is required so that the response will reliably be closed.

Making custom/undocumented requests

This library is typed for convenient access to the documented API.

If you need to access undocumented endpoints, params, or response properties, the library can still be used.

Undocumented endpoints

To make requests to undocumented endpoints, you can make requests using client.get, client.post, and other http verbs. Options on the client will be respected (such as retries) when making this request.

import httpx

response = client.post(
    "/foo",
    cast_to=httpx.Response,
    body={"my_param": True},
)

print(response.headers.get("x-foo"))

Undocumented request params

If you want to explicitly send an extra param, you can do so with the extra_query, extra_body, and extra_headers request options.

Undocumented response properties

To access undocumented response properties, you can access the extra fields like response.unknown_prop. You can also get all the extra fields on the Pydantic model as a dict with response.model_extra.

Configuring the HTTP client

You can directly override the httpx client to customize it for your use case, including:

import httpx
from runloop_api_client import Runloop, DefaultHttpxClient

client = Runloop(
    # Or use the `RUNLOOP_BASE_URL` env var
    base_url="http://my.test.server.example.com:8083",
    http_client=DefaultHttpxClient(
        proxy="http://my.test.proxy.example.com",
        transport=httpx.HTTPTransport(local_address="0.0.0.0"),
    ),
)

You can also customize the client on a per-request basis by using with_options():

client.with_options(http_client=DefaultHttpxClient(...))

Managing HTTP resources

By default the library closes underlying HTTP connections whenever the client is garbage collected. You can manually close the client using the .close() method if desired, or with a context manager that closes when exiting.

from runloop_api_client import Runloop

with Runloop() as client:
  # make requests here
  ...

# HTTP client is now closed

Versioning

This package generally follows SemVer conventions, though certain backwards-incompatible changes may be released as minor versions:

  1. Changes that only affect static types, without breaking runtime behavior.
  2. Changes to library internals which are technically public but not intended or documented for external use. (Please open a GitHub issue to let us know if you are relying on such internals.)
  3. Changes that we do not expect to impact the vast majority of users in practice.

We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.

We are keen for your feedback; please open an issue with questions, bugs, or suggestions.

Determining the installed version

If you've upgraded to the latest version but aren't seeing any new features you were expecting then your python environment is likely still using an older version.

You can determine the version that is being used at runtime with:

import runloop_api_client
print(runloop_api_client.__version__)

Requirements

Python 3.9 or higher.

Development

After cloning the repository, run the bootstrap script and install git hooks:

./scripts/bootstrap
./scripts/install-hooks

This installs pre-push hooks that run linting and verify generated files are up to date.

Contributing

See the contributing documentation.

1.21.0 May 13, 2026
1.20.3 May 08, 2026
1.20.2 May 01, 2026
1.20.1 May 01, 2026
1.20.0 Apr 21, 2026
1.19.0 Apr 13, 2026
1.18.1 Apr 10, 2026
1.17.0 Apr 09, 2026
1.16.0 Apr 03, 2026
1.15.0 Apr 02, 2026
1.14.1 Apr 01, 2026
1.14.0 Mar 31, 2026
1.13.3 Mar 26, 2026
1.13.2 Mar 25, 2026
1.13.1 Mar 25, 2026
1.13.0 Mar 25, 2026
1.12.1 Mar 19, 2026
1.12.0 Mar 18, 2026
1.11.0 Mar 11, 2026
1.10.3 Feb 27, 2026
1.10.2 Feb 26, 2026
1.10.1 Feb 26, 2026
1.10.0 Feb 26, 2026
1.9.0 Feb 25, 2026
1.8.0 Feb 12, 2026
1.7.0 Feb 05, 2026
1.5.1 Jan 30, 2026
1.5.0 Jan 30, 2026
1.4.0 Jan 30, 2026
1.3.2 Jan 30, 2026
1.3.1 Jan 28, 2026
1.3.0 Jan 22, 2026
1.3.0a0 Jan 20, 2026
1.2.0 Dec 09, 2025
1.1.0 Dec 06, 2025
1.0.0 Dec 02, 2025
0.69.0 Nov 21, 2025
0.68.0 Nov 19, 2025
0.67.0 Nov 17, 2025
0.66.1 Oct 23, 2025
0.66.0 Oct 23, 2025
0.65.0 Oct 15, 2025
0.64.0 Oct 06, 2025
0.63.0 Oct 02, 2025
0.62.0 Oct 01, 2025
0.61.0 Sep 30, 2025
0.60.1 Sep 29, 2025
0.60.0 Sep 10, 2025
0.59.0 Sep 09, 2025
0.58.0 Sep 04, 2025
0.57.0 Aug 27, 2025
0.56.2 Aug 25, 2025
0.56.1b0 Aug 21, 2025
0.55.2 Aug 20, 2025
0.55.1 Aug 19, 2025
0.55.0 Aug 19, 2025
0.54.0 Aug 05, 2025
0.53.0 Jul 30, 2025
0.52.0 Jul 30, 2025
0.51.0 Jul 29, 2025
0.50.0 Jul 15, 2025
0.49.0 Jul 15, 2025
0.48.2 Jul 11, 2025
0.48.1 Jul 11, 2025
0.48.0 Jul 09, 2025
0.47.1 Jul 08, 2025
0.47.0 Jul 01, 2025
0.46.0 Jul 01, 2025
0.45.0 Jun 24, 2025
0.44.0 Jun 23, 2025
0.43.0 Jun 14, 2025
0.42.0 Jun 11, 2025
0.41.0 Jun 10, 2025
0.40.0 Jun 10, 2025
0.39.0 Jun 04, 2025
0.38.0 Jun 04, 2025
0.37.0 Jun 04, 2025
0.36.0 Jun 02, 2025
0.35.0 May 30, 2025
0.34.1 May 30, 2025
0.34.0 May 27, 2025
0.33.0 May 22, 2025
0.32.0 Apr 25, 2025
0.31.0 Apr 21, 2025
0.30.0 Apr 16, 2025
0.29.0 Mar 25, 2025
0.28.0 Mar 21, 2025
0.27.0 Mar 21, 2025
0.26.0 Mar 04, 2025
0.25.0 Feb 26, 2025
0.24.0 Feb 19, 2025
0.23.0 Feb 11, 2025
0.22.0 Feb 04, 2025
0.21.0 Feb 04, 2025
0.20.0 Feb 04, 2025
0.19.0 Feb 03, 2025
0.18.0 Feb 01, 2025
0.17.0 Feb 01, 2025
0.16.0 Jan 31, 2025
0.15.0 Jan 29, 2025
0.14.0 Jan 29, 2025
0.13.0 Jan 15, 2025
0.12.0 Jan 07, 2025
0.11.0 Nov 29, 2024
0.10.0 Nov 08, 2024
0.9.0 Nov 07, 2024
0.8.0 Nov 06, 2024
0.7.0 Oct 24, 2024
0.6.0 Oct 23, 2024
0.5.0 Oct 22, 2024
0.4.0 Oct 22, 2024
0.3.0 Oct 14, 2024
0.2.2 Oct 11, 2024
0.2.0 Oct 10, 2024
0.1.0a23 Oct 07, 2024
0.1.0a22 Oct 01, 2024
0.1.0a21 Oct 01, 2024
0.1.0a20 Sep 06, 2024
0.1.0a19 Aug 28, 2024
0.1.0a18 Aug 28, 2024
0.1.0a17 Aug 28, 2024
0.1.0a16 Aug 26, 2024
0.1.0a15 Aug 23, 2024
0.1.0a14 Aug 23, 2024
0.1.0a13 Aug 16, 2024
0.1.0a12 Aug 15, 2024
0.1.0a11 Aug 07, 2024
0.1.0a10 Aug 02, 2024
0.1.0a9 Aug 01, 2024
0.1.0a8 Aug 01, 2024
0.1.0a7 Jul 30, 2024
0.1.0a6 Jul 25, 2024
0.1.0a5 Jul 11, 2024
0.1.0a4 Jun 26, 2024
0.1.0a3 Jun 26, 2024
Extras:
Dependencies:
anyio (<5,>=3.5.0)
distro (<2,>=1.7.0)
httpx[http2] (<1,>=0.23.0)
pydantic (<3,>=2.0)
sniffio
typing-extensions (<5,>=4.14)
uuid-utils (>=0.11.0)