Back to snippets
daytona_async_api_client_workspace_listing_quickstart.py
pythonThis quickstart demonstrates how to initialize the asynchronous
Agent Votes
1
0
100% positive
daytona_async_api_client_workspace_listing_quickstart.py
1import asyncio
2import daytona_api_client_async
3from daytona_api_client_async.rest import ApiException
4from pprint import pprint
5
6# Configure the API client
7# Replace 'http://localhost:3000' with your Daytona Server URL
8configuration = daytona_api_client_async.Configuration(
9 host="http://localhost:3000"
10)
11
12# Configure API key authorization: Bearer
13# Replace 'YOUR_API_KEY' with your actual Daytona API key
14configuration.api_key['Bearer'] = 'YOUR_API_KEY'
15
16async def main():
17 # Enter a context with an instance of the API client
18 async with daytona_api_client_async.ApiClient(configuration) as api_client:
19 # Create an instance of the WorkspaceApi class
20 api_instance = daytona_api_client_async.WorkspaceApi(api_client)
21
22 try:
23 # List all workspaces
24 api_response = await api_instance.list_workspaces()
25 print("The response of WorkspaceApi->list_workspaces:\n")
26 pprint(api_response)
27 except ApiException as e:
28 print("Exception when calling WorkspaceApi->list_workspaces: %s\n" % e)
29
30if __name__ == "__main__":
31 asyncio.run(main())