Daytona Toolbox API Client (Async)
The `daytona-toolbox-api-client-async` library provides an asynchronous Python client for interacting with the Daytona Toolbox API. It allows programmatic access to manage developer environments, workspaces, and other Daytona resources. The library is frequently updated, often with daily or near-daily releases aligning with the main Daytona platform.
Warnings
- deprecated This `daytona-toolbox-api-client-async` package appears to be superseded by the `daytona-sdk` package. The official Daytona GitHub repository and recent release notes consistently refer to `sdk-python`, which corresponds to the `daytona-sdk` PyPI package. Users are advised to migrate to `daytona-sdk` for future compatibility and features.
- gotcha This is an *asynchronous* client. All API calls are coroutines and must be `await`ed within an `async` function. The main execution must be wrapped in `asyncio.run()`.
- gotcha Authentication is mandatory for most Daytona API calls. You must provide a valid API token (or similar credentials) to the `Client` constructor. Failing to do so will result in authentication errors.
Install
-
pip install daytona-toolbox-api-client-async
Imports
- Client
from daytona_toolbox_api_client_async import Client
Quickstart
import asyncio
import os
from daytona_toolbox_api_client_async import Client
async def main():
# It's recommended to set API_TOKEN and BASE_URL as environment variables
api_token = os.environ.get('DAYTONA_API_TOKEN', 'YOUR_API_TOKEN')
base_url = os.environ.get('DAYTONA_BASE_URL', 'http://localhost:3000') # Adjust if your Daytona instance is elsewhere
if api_token == 'YOUR_API_TOKEN':
print("Warning: Please set DAYTONA_API_TOKEN environment variable or replace 'YOUR_API_TOKEN'.")
try:
client = Client(base_url=base_url, token=api_token)
# Example: List available workspaces (requires authentication)
print(f"Attempting to list workspaces from {base_url}...")
workspaces_page = await client.workspaces.list()
# Access items from the paginated response
if workspaces_page.items:
print(f"Found {len(workspaces_page.items)} workspaces.")
for workspace in workspaces_page.items:
print(f" - Workspace ID: {workspace.id}, Name: {workspace.name}")
else:
print("No workspaces found or accessible.")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure your DAYTONA_API_TOKEN and DAYTONA_BASE_URL are correct and the Daytona API is running.")
if __name__ == "__main__":
asyncio.run(main())