[{"data":1,"prerenderedAt":666},["ShallowReactive",2],{"navigation_docs":3,"-sdk-bulk-imports":223,"-sdk-bulk-imports-surround":661},[4,30,83,128,157,182],{"title":5,"path":6,"stem":7,"children":8,"page":29},"Getting Started","\u002Fgetting-started","1.getting-started",[9,13,17,21,25],{"title":10,"path":11,"stem":12},"What is FlashDrive?","\u002Fgetting-started\u002Fwhat-is-flashdrive","1.getting-started\u002F01.what-is-flashdrive",{"title":14,"path":15,"stem":16},"Quickstart","\u002Fgetting-started\u002Fquickstart","1.getting-started\u002F02.quickstart",{"title":18,"path":19,"stem":20},"Key concepts","\u002Fgetting-started\u002Fkey-concepts","1.getting-started\u002F03.key-concepts",{"title":22,"path":23,"stem":24},"Find files","\u002Fgetting-started\u002Ffind-files","1.getting-started\u002F04.find-files",{"title":26,"path":27,"stem":28},"Common use cases","\u002Fgetting-started\u002Fuse-cases","1.getting-started\u002F05.use-cases",false,{"title":31,"path":32,"stem":33,"children":34,"page":29},"Platform Guide","\u002Fplatform","2.platform",[35,39,43,47,51,55,59,63,67,71,75,79],{"title":36,"path":37,"stem":38},"Organizations and workspaces","\u002Fplatform\u002Forganizations-and-workspaces","2.platform\u002F01.organizations-and-workspaces",{"title":40,"path":41,"stem":42},"Members, invitations, and roles","\u002Fplatform\u002Fmembers-and-roles","2.platform\u002F02.members-and-roles",{"title":44,"path":45,"stem":46},"API keys and permissions","\u002Fplatform\u002Fapi-keys","2.platform\u002F03.api-keys",{"title":48,"path":49,"stem":50},"Drives and the default drive","\u002Fplatform\u002Fdrives-and-defaults","2.platform\u002F04.drives-and-defaults",{"title":52,"path":53,"stem":54},"Folders and files","\u002Fplatform\u002Ffolders-and-documents","2.platform\u002F05.folders-and-documents",{"title":56,"path":57,"stem":58},"Upload files","\u002Fplatform\u002Fuploads-and-indexing","2.platform\u002F06.uploads-and-processing",{"title":60,"path":61,"stem":62},"Usage","\u002Fplatform\u002Fusage","2.platform\u002F07.usage",{"title":64,"path":65,"stem":66},"Billing and credits","\u002Fplatform\u002Fbilling","2.platform\u002F08.billing",{"title":68,"path":69,"stem":70},"Storage and limits","\u002Fplatform\u002Fstorage-and-upgrades","2.platform\u002F09.storage-and-upgrades",{"title":72,"path":73,"stem":74},"Account settings and security","\u002Fplatform\u002Faccount-and-security","2.platform\u002F10.account-and-security",{"title":76,"path":77,"stem":78},"Redeem a promo code","\u002Fplatform\u002Fpromo-codes","2.platform\u002F11.promo-codes",{"title":80,"path":81,"stem":82},"Build tools from files","\u002Fplatform\u002Ffile-workflows","2.platform\u002F12.file-workflows",{"title":84,"path":85,"stem":86,"children":87,"page":29},"SDK Guide","\u002Fsdk","4.sdk",[88,92,96,100,104,108,112,116,120,124],{"title":89,"path":90,"stem":91},"Python installation and configuration","\u002Fsdk\u002Finstallation","4.sdk\u002F01.installation",{"title":93,"path":94,"stem":95},"Upload your first files","\u002Fsdk\u002Fupload-files","4.sdk\u002F02.upload-files",{"title":97,"path":98,"stem":99},"Upload a large collection","\u002Fsdk\u002Fbulk-imports","4.sdk\u002F03.bulk-imports",{"title":101,"path":102,"stem":103},"Find, read and edit files","\u002Fsdk\u002Ffiles","4.sdk\u002F05.files",{"title":105,"path":106,"stem":107},"Work with folders","\u002Fsdk\u002Ffolders","4.sdk\u002F06.folders",{"title":109,"path":110,"stem":111},"Manage drives and defaults","\u002Fsdk\u002Fdrives-and-defaults","4.sdk\u002F07.drives-and-defaults",{"title":113,"path":114,"stem":115},"Replace files and attach metadata","\u002Fsdk\u002Freplace-and-label","4.sdk\u002F08.replace-and-label",{"title":117,"path":118,"stem":119},"Upload recovery and partial failures","\u002Fsdk\u002Fupload-recovery","4.sdk\u002F09.upload-recovery",{"title":121,"path":122,"stem":123},"Async workflows","\u002Fsdk\u002Fasync","4.sdk\u002F10.async",{"title":125,"path":126,"stem":127},"Errors, timeouts, and retries","\u002Fsdk\u002Ferrors-and-retries","4.sdk\u002F11.errors-and-retries",{"title":129,"path":130,"stem":131,"children":132,"page":29},"CLI Guide","\u002Fcli","5.cli",[133,137,141,145,149,153],{"title":134,"path":135,"stem":136},"Get Started","\u002Fcli\u002Fquickstart","5.cli\u002F01.quickstart",{"title":138,"path":139,"stem":140},"Profiles and Access","\u002Fcli\u002Fconfiguration","5.cli\u002F02.configuration",{"title":142,"path":143,"stem":144},"Uploads and Recovery","\u002Fcli\u002Fuploads-and-recovery","5.cli\u002F03.uploads-and-recovery",{"title":146,"path":147,"stem":148},"Mount and Sync","\u002Fcli\u002Fmount-and-sync","5.cli\u002F05.mount-and-sync",{"title":150,"path":151,"stem":152},"Sandbox Tokens","\u002Fcli\u002Fsandboxes","5.cli\u002F06.sandboxes",{"title":154,"path":155,"stem":156},"Command Reference","\u002Fcli\u002Fcommands","5.cli\u002F07.commands",{"title":158,"path":159,"stem":160,"children":161,"page":29},"MCP","\u002Fmcp","6.mcp",[162,166,170,174,178],{"title":163,"path":164,"stem":165},"Connect an AI client","\u002Fmcp\u002Fconnect","6.mcp\u002F01.connect",{"title":167,"path":168,"stem":169},"Choose an assistant’s permissions","\u002Fmcp\u002Fpermissions","6.mcp\u002F02.permissions",{"title":171,"path":172,"stem":173},"Upload and manage content","\u002Fmcp\u002Fmanage-content","6.mcp\u002F04.manage-content",{"title":175,"path":176,"stem":177},"Tool reference","\u002Fmcp\u002Ftools","6.mcp\u002F05.tools",{"title":179,"path":180,"stem":181},"Troubleshooting and revoking access","\u002Fmcp\u002Ftroubleshooting","6.mcp\u002F06.troubleshooting",{"title":183,"path":184,"stem":185,"children":186,"page":29},"Reference","\u002Freference","7.reference",[187,191,195,199,203,207,211,215,219],{"title":188,"path":189,"stem":190},"Authentication and API conventions","\u002Freference\u002Fauthentication","7.reference\u002F01.authentication",{"title":192,"path":193,"stem":194},"Organizations, workspaces, and access API","\u002Freference\u002Faccess-api","7.reference\u002F02.access-api",{"title":196,"path":197,"stem":198},"Drives, folders, and files API","\u002Freference\u002Fcontent-api","7.reference\u002F03.content-api",{"title":200,"path":201,"stem":202},"Uploads API","\u002Freference\u002Fuploads-api","7.reference\u002F04.uploads-api",{"title":204,"path":205,"stem":206},"Usage and billing API","\u002Freference\u002Fusage-and-billing-api","7.reference\u002F06.usage-and-billing-api",{"title":208,"path":209,"stem":210},"Errors and recovery","\u002Freference\u002Ferrors","7.reference\u002F07.errors",{"title":212,"path":213,"stem":214},"Limits and supported files","\u002Freference\u002Flimits","7.reference\u002F08.limits",{"title":216,"path":217,"stem":218},"Troubleshooting","\u002Freference\u002Ftroubleshooting","7.reference\u002F09.troubleshooting",{"title":220,"path":221,"stem":222},"Changelog","\u002Freference\u002Fchangelog","7.reference\u002F10.changelog",{"id":224,"title":97,"body":225,"description":654,"extension":655,"links":656,"meta":657,"navigation":658,"path":98,"seo":659,"stem":99,"__hash__":660},"docs\u002F4.sdk\u002F03.bulk-imports.md",{"type":226,"value":227,"toc":647},"minimark",[228,232,279,297,302,309,332,346,350,525,546,557,561,564,592,595,599,623,633,637,643],[229,230,231],"p",{},"These examples use the latest stable release of the Python SDK.",[229,233,234,238,239,242,243,246,247,250,251,254,255,258,259,262,263,266,267,270,271,274,275,278],{},[235,236,237],"code",{},"client.upload()"," handles large collections: one call takes up to 100,000 files, and the SDK groups the requests of a multi-file upload into bulk requests of up to 1,000 files each. By default (",[235,240,241],{},"route=\"auto\"","), a batch of at least 1,000 files or 1 GB, all of them text files, goes through a bulk import: read ",[235,244,245],{},"batch.import_status",", as ",[235,248,249],{},"batch.files"," is empty, and pass ",[235,252,253],{},"journal="," to make it resumable. Pass ",[235,256,257],{},"route=\"uploads\""," for a receipt per file. ",[235,260,261],{},"client.imports"," plans, runs and resumes bulk imports directly; a stopped import raises ",[235,264,265],{},"BulkImportError"," with the ",[235,268,269],{},"import_id",", ",[235,272,273],{},"drive_id"," and ",[235,276,277],{},"journal"," to resume from. This page shows how to copy a local folder tree into a drive, keep its folders, and resume after an interruption.",[229,280,281,282,286,287,296],{},"For a few files, see ",[283,284,285],"a",{"href":94},"upload files",". To keep a local folder and a drive in step from a terminal, use ",[283,288,289,290,274,293],{"href":147},"a mount or ",[235,291,292],{},"flashdrive pull",[235,294,295],{},"flashdrive push",".",[298,299,301],"h2",{"id":300},"check-the-drive-has-room","Check the drive has room",[229,303,304,305,308],{},"A drive holds up to 500,000 files and 1 TB, and each file can be up to 10,000,000,000 bytes. Read the values the service currently enforces with ",[235,306,307],{},"client.limits()",":",[310,311,316],"pre",{"className":312,"code":313,"language":314,"meta":315,"style":315},"language-python shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","limits = client.limits()\nprint(limits.max_drive_documents, limits.max_drive_source_bytes, limits.max_file_bytes)\n","python","",[235,317,318,326],{"__ignoreMap":315},[319,320,323],"span",{"class":321,"line":322},"line",1,[319,324,325],{},"limits = client.limits()\n",[319,327,329],{"class":321,"line":328},2,[319,330,331],{},"print(limits.max_drive_documents, limits.max_drive_source_bytes, limits.max_file_bytes)\n",[229,333,334,335,338,339,342,343,296],{},"Each client fetches limits at most once an hour; pass ",[235,336,337],{},"refresh=True"," to fetch them again. Treat them as an early warning: the service has the final say, and refuses growth past a drive limit with code ",[235,340,341],{},"drive_limit_exceeded",", or past your workspace's storage with ",[235,344,345],{},"storage_capacity_exceeded",[298,347,349],{"id":348},"upload-a-folder-tree","Upload a folder tree",[310,351,353],{"className":312,"code":352,"language":314,"meta":315,"style":315},"import hashlib\nfrom collections import defaultdict\nfrom pathlib import Path\nfrom flashdrive import Flashdrive\n\nroot = Path(\"library\")\nfiles = sorted(p for p in root.rglob(\"*\") if p.is_file())\n\n# Group the files by their folder, relative to the root.\nby_folder = defaultdict(list)\nfor path in files:\n    by_folder[path.parent.relative_to(root).as_posix()].append(path)\n\nwith Flashdrive(drive_id=\"DRIVE_UUID\") as client:\n    folder_paths = sorted(p for p in by_folder if p != \".\")\n    folder_ids = {}\n    for start in range(0, len(folder_paths), 500):\n        for made in client.folders.ensure(folder_paths[start:start + 500]):\n            folder_ids[made.path] = made.id\n\n    for relative, paths in sorted(by_folder.items()):\n        client.upload(\n            paths,\n            folder_id=folder_ids.get(relative),       # None: the top of the drive\n            concurrency=10,\n            timeout=3600,\n            processing_timeout=3600,\n            idempotency_key=\"library-1:\" + hashlib.sha256(relative.encode()).hexdigest()[:32],\n        )\n",[235,354,355,360,365,371,377,384,390,396,401,407,413,419,425,430,436,442,448,454,460,466,471,477,483,489,495,501,507,513,519],{"__ignoreMap":315},[319,356,357],{"class":321,"line":322},[319,358,359],{},"import hashlib\n",[319,361,362],{"class":321,"line":328},[319,363,364],{},"from collections import defaultdict\n",[319,366,368],{"class":321,"line":367},3,[319,369,370],{},"from pathlib import Path\n",[319,372,374],{"class":321,"line":373},4,[319,375,376],{},"from flashdrive import Flashdrive\n",[319,378,380],{"class":321,"line":379},5,[319,381,383],{"emptyLinePlaceholder":382},true,"\n",[319,385,387],{"class":321,"line":386},6,[319,388,389],{},"root = Path(\"library\")\n",[319,391,393],{"class":321,"line":392},7,[319,394,395],{},"files = sorted(p for p in root.rglob(\"*\") if p.is_file())\n",[319,397,399],{"class":321,"line":398},8,[319,400,383],{"emptyLinePlaceholder":382},[319,402,404],{"class":321,"line":403},9,[319,405,406],{},"# Group the files by their folder, relative to the root.\n",[319,408,410],{"class":321,"line":409},10,[319,411,412],{},"by_folder = defaultdict(list)\n",[319,414,416],{"class":321,"line":415},11,[319,417,418],{},"for path in files:\n",[319,420,422],{"class":321,"line":421},12,[319,423,424],{},"    by_folder[path.parent.relative_to(root).as_posix()].append(path)\n",[319,426,428],{"class":321,"line":427},13,[319,429,383],{"emptyLinePlaceholder":382},[319,431,433],{"class":321,"line":432},14,[319,434,435],{},"with Flashdrive(drive_id=\"DRIVE_UUID\") as client:\n",[319,437,439],{"class":321,"line":438},15,[319,440,441],{},"    folder_paths = sorted(p for p in by_folder if p != \".\")\n",[319,443,445],{"class":321,"line":444},16,[319,446,447],{},"    folder_ids = {}\n",[319,449,451],{"class":321,"line":450},17,[319,452,453],{},"    for start in range(0, len(folder_paths), 500):\n",[319,455,457],{"class":321,"line":456},18,[319,458,459],{},"        for made in client.folders.ensure(folder_paths[start:start + 500]):\n",[319,461,463],{"class":321,"line":462},19,[319,464,465],{},"            folder_ids[made.path] = made.id\n",[319,467,469],{"class":321,"line":468},20,[319,470,383],{"emptyLinePlaceholder":382},[319,472,474],{"class":321,"line":473},21,[319,475,476],{},"    for relative, paths in sorted(by_folder.items()):\n",[319,478,480],{"class":321,"line":479},22,[319,481,482],{},"        client.upload(\n",[319,484,486],{"class":321,"line":485},23,[319,487,488],{},"            paths,\n",[319,490,492],{"class":321,"line":491},24,[319,493,494],{},"            folder_id=folder_ids.get(relative),       # None: the top of the drive\n",[319,496,498],{"class":321,"line":497},25,[319,499,500],{},"            concurrency=10,\n",[319,502,504],{"class":321,"line":503},26,[319,505,506],{},"            timeout=3600,\n",[319,508,510],{"class":321,"line":509},27,[319,511,512],{},"            processing_timeout=3600,\n",[319,514,516],{"class":321,"line":515},28,[319,517,518],{},"            idempotency_key=\"library-1:\" + hashlib.sha256(relative.encode()).hexdigest()[:32],\n",[319,520,522],{"class":321,"line":521},29,[319,523,524],{},"        )\n",[229,526,527,530,531,534,535,274,538,541,542,545],{},[235,528,529],{},"folders.ensure()"," creates every folder path that is missing, reuses the ones that exist, and returns a ",[235,532,533],{},"FolderPath"," (",[235,536,537],{},"path",[235,539,540],{},"id",") for each. It takes up to 500 paths per call. See ",[283,543,544],{"href":106},"folders"," for the naming rules.",[229,547,548,549,552,553,556],{},"Each ",[235,550,551],{},"upload()"," call above sends one folder's files with a key derived from the folder's path. A key is 1 to 128 visible ASCII characters, so the example hashes the path. Keep the key, the file list and its order the same when you run the script again, so a retry finds the work already done and nothing is uploaded twice. Use a new prefix, such as ",[235,554,555],{},"library-2",", for a new copy of the collection.",[298,558,560],{"id":559},"resume-after-an-interruption","Resume after an interruption",[229,562,563],{},"If the script stops, run it again unchanged. For each folder:",[565,566,567,571,574],"ul",{},[568,569,570],"li",{},"Files the service already accepted are not uploaded again: the same key and the same ordered file list identify the same uploads.",[568,572,573],{},"Files whose transfer did not finish are sent again.",[568,575,576,577,580,581,584,585,588,589,296],{},"An ",[235,578,579],{},"UploadBatchError"," keeps the files that succeeded in ",[235,582,583],{},"exc.batch.files"," and the failures in ",[235,586,587],{},"exc.failures","; see ",[283,590,591],{"href":118},"upload recovery",[229,593,594],{},"Unfinished upload sessions and request keys last 24 hours. After that, a rerun with the same key starts new uploads, so finish or check an interrupted collection within a day, and follow already-queued files by their saved receipts.",[298,596,598],{"id":597},"choose-batch-sizes","Choose batch sizes",[565,600,601,604,610,620],{},[568,602,603],{},"Keep each call to a size you are happy to retry. A folder at a time works well; split a very large folder into several calls, each with its own key and a fixed file order.",[568,605,606,609],{},[235,607,608],{},"concurrency"," (1 to 50, default 3) sets how many files one call transfers at once. Raise it for many small files.",[568,611,612,615,616,619],{},[235,613,614],{},"timeout"," covers the transfers of the whole call and ",[235,617,618],{},"processing_timeout"," the processing after them. Raise both for large batches.",[568,621,622],{},"Several calls running at the same time share the drive's upload capacity. The SDK waits for capacity on its own and retries with the same key.",[229,624,625,626,629,630,296],{},"Uploading the same file again without its ",[235,627,628],{},"external_id"," creates a second file. To update files you uploaded before, see ",[283,631,632],{"href":114},"replace files",[298,634,636],{"id":635},"writes-while-you-upload","Writes while you upload",[229,638,639,640,296],{},"Other people and agents can keep working in the drive while a large upload runs. To see what changed while your script ran, read the drive's ",[283,641,642],{"href":102},"change feed",[644,645,646],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":315,"searchDepth":328,"depth":328,"links":648},[649,650,651,652,653],{"id":300,"depth":328,"text":301},{"id":348,"depth":328,"text":349},{"id":559,"depth":328,"text":560},{"id":597,"depth":328,"text":598},{"id":635,"depth":328,"text":636},"Upload a local folder tree of thousands of files into a drive, with resumable batches.","md",null,{},{"title":97},{"title":97,"description":654},"mcXtQ-GvXxlymwGzhensvSSCex6YJDyUuXcbck6n21U",[662,664],{"title":93,"path":94,"stem":95,"description":663,"children":-1},"Upload one or several files of any type and follow their progress.",{"title":101,"path":102,"stem":103,"description":665,"children":-1},"List and glob files, grep and read them by line, stream and download bytes, edit in place and follow changes.",1795366545825]