Skip to Content
Python SDKAsync applications

Use the async client

Use AsyncFlashdrive inside an async application. It accepts the same API key, base URL, and drive settings as Flashdrive. Its network methods are awaited, and async with closes the client when you finish.

After configuring your environment, save this as async_search.py and run python async_search.py:

import asyncio import os from flashdrive import AsyncFlashdrive async def main(): async with AsyncFlashdrive( drive_id=os.environ["FLASHDRIVE_DRIVE_ID"] ) as client: page = await client.files.full_text_search("time off request") for match in page.results: print(match.path, match.start_line, match.text) if __name__ == "__main__": asyncio.run(main())

In an application that already has an event loop, call await main() from async code instead of starting another loop with asyncio.run().

Bound concurrent reads

Use a small concurrency limit for independent work. This example lists one page of files, then reads up to five text excerpts with at most three requests in flight:

import asyncio import os from flashdrive import AsyncFlashdrive async def main(): async with AsyncFlashdrive( drive_id=os.environ["FLASHDRIVE_DRIVE_ID"] ) as client: page = await client.files.glob("**/*.md", limit=5) limit = asyncio.Semaphore(3) async def read_excerpt(file): async with limit: text = await client.files.read( file.document_id, start_line=1, line_count=20, revision=file.revision, ) return file.path, text.text excerpts = await asyncio.gather(*(read_excerpt(file) for file in page.files)) for path, text in excerpts: print(path, text) if __name__ == "__main__": asyncio.run(main())

Uploads use await client.upload(...) and retain the same receipts and timeout options as the upload guide. Concurrent calls can still encounter workspace limits. Handle rate limits and partial failures, and avoid sending parallel updates to the same file without reconciling revisions.