Skip to content

Commit 8783383

Browse files
authored
docs: Improve Python async example for ToolboxClient usage (googleapis#2021)
Refactor Python example to use an async main function for `ToolboxClient`, which is an async client and needs to be called from an `async` function. This PR fixes that by putting this function call in an async `main` function.
1 parent 628539b commit 8783383

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

docs/en/how-to/deploy_toolbox.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,23 @@ You can connect to Toolbox Cloud Run instances directly through the SDK.
162162
163163
{{< tabpane persist=header >}}
164164
{{< tab header="Python" lang="python" >}}
165+
import asyncio
165166
from toolbox_core import ToolboxClient, auth_methods
166167
167168
# Replace with the Cloud Run service URL generated in the previous step
168-
169169
URL = "https://cloud-run-url.app"
170170
171171
auth_token_provider = auth_methods.aget_google_id_token(URL) # can also use sync method
172172
173-
async with ToolboxClient(
174-
URL,
175-
client_headers={"Authorization": auth_token_provider},
176-
) as toolbox:
173+
async def main():
174+
async with ToolboxClient(
175+
URL,
176+
client_headers={"Authorization": auth_token_provider},
177+
) as toolbox:
178+
toolset = await toolbox.load_toolset()
179+
# ...
180+
181+
asyncio.run(main())
177182
{{< /tab >}}
178183
{{< tab header="Javascript" lang="javascript" >}}
179184
import { ToolboxClient } from '@toolbox-sdk/core';

0 commit comments

Comments
 (0)