Daytona Toolbox API Client (Async)

0.164.0 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart initializes the asynchronous client and attempts to list workspaces. It uses environment variables for authentication (`DAYTONA_API_TOKEN`) and the API endpoint (`DAYTONA_BASE_URL`), which is the recommended practice. Replace placeholder values or set environment variables before running.

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())

view raw JSON →