[{"data":1,"prerenderedAt":808},["ShallowReactive",2],{"navigation_docs":3,"-sdk-replace-and-label":223,"-sdk-replace-and-label-surround":803},[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":113,"body":225,"description":796,"extension":797,"links":798,"meta":799,"navigation":800,"path":114,"seo":801,"stem":115,"__hash__":802},"docs\u002F4.sdk\u002F08.replace-and-label.md",{"type":226,"value":227,"toc":785},"minimark",[228,232,249,254,332,361,403,407,432,451,458,462,480,498,502,509,554,577,581,612,630,635,664,688,692,755,759,768,781],[229,230,231],"p",{},"These examples use the latest stable release of the Python SDK.",[229,233,234,235,239,240,243,244,248],{},"A file keeps its document ID, ",[236,237,238],"code",{},"external_id",", metadata and folder when you replace its contents. ",[236,241,242],{},"client.documents"," replaces and deletes files by ID and checks that nobody changed them since you read them. To change part of a file, ",[245,246,247],"a",{"href":102},"edit it in place",".",[250,251,253],"h2",{"id":252},"replace-the-version-you-read","Replace the version you read",[255,256,261],"pre",{"className":257,"code":258,"language":259,"meta":260,"style":260},"language-python shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","from flashdrive import Flashdrive\n\nwith Flashdrive(drive_id=\"DRIVE_UUID\") as client:\n    observed = client.documents.get(\"DOCUMENT_UUID\")\n    receipt = client.documents.replace_file(\n        \"DOCUMENT_UUID\",\n        \"policy-v2.pdf\",\n        expected_revision=observed.latest_revision,\n        idempotency_key=\"refund-policy-edition-2\",\n    )\n    print(receipt.document_id, receipt.status)\n","python","",[236,262,263,271,278,284,290,296,302,308,314,320,326],{"__ignoreMap":260},[264,265,268],"span",{"class":266,"line":267},"line",1,[264,269,270],{},"from flashdrive import Flashdrive\n",[264,272,274],{"class":266,"line":273},2,[264,275,277],{"emptyLinePlaceholder":276},true,"\n",[264,279,281],{"class":266,"line":280},3,[264,282,283],{},"with Flashdrive(drive_id=\"DRIVE_UUID\") as client:\n",[264,285,287],{"class":266,"line":286},4,[264,288,289],{},"    observed = client.documents.get(\"DOCUMENT_UUID\")\n",[264,291,293],{"class":266,"line":292},5,[264,294,295],{},"    receipt = client.documents.replace_file(\n",[264,297,299],{"class":266,"line":298},6,[264,300,301],{},"        \"DOCUMENT_UUID\",\n",[264,303,305],{"class":266,"line":304},7,[264,306,307],{},"        \"policy-v2.pdf\",\n",[264,309,311],{"class":266,"line":310},8,[264,312,313],{},"        expected_revision=observed.latest_revision,\n",[264,315,317],{"class":266,"line":316},9,[264,318,319],{},"        idempotency_key=\"refund-policy-edition-2\",\n",[264,321,323],{"class":266,"line":322},10,[264,324,325],{},"    )\n",[264,327,329],{"class":266,"line":328},11,[264,330,331],{},"    print(receipt.document_id, receipt.status)\n",[229,333,334,337,338,341,342,344,345,348,349,352,353,356,357,360],{},[236,335,336],{},"documents.replace_file(document_id, path, *, expected_revision, wait=True, timeout=600, idempotency_key=None, drive_id=None)"," uploads ",[236,339,340],{},"path"," as the file's new contents. It copies the file's ",[236,343,238],{},", metadata and folder to the new contents; facts the service reads from a stored file, such as ",[236,346,347],{},"media."," keys, are read again from the new file. It returns one ",[236,350,351],{},"UploadReceipt",". By default it waits until processing finishes; ",[236,354,355],{},"wait=False"," returns once the upload is accepted. ",[236,358,359],{},"timeout"," covers the whole call.",[229,362,363,366,367,370,371,374,375,378,379,382,383,386,387,390,391,394,395,398,399,402],{},[236,364,365],{},"expected_revision"," is required: pass the ",[236,368,369],{},"latest_revision"," from your earlier ",[236,372,373],{},"documents.get()",", or the ",[236,376,377],{},"revision"," from ",[236,380,381],{},"files.list",", ",[236,384,385],{},"files.glob"," or ",[236,388,389],{},"files.read",". Without it the SDK raises ",[236,392,393],{},"ValueError"," before sending anything. If the file changed since your read, the call raises a ",[236,396,397],{},"PreconditionFailedError"," with code ",[236,400,401],{},"stale_version"," and nothing is written. The SDK never fetches a newer revision for you; read the file again and decide whether your change still applies. Treat revisions as opaque strings.",[250,404,406],{"id":405},"an-upload-never-replaces-a-file","An upload never replaces a file",[229,408,409,410,412,413,416,417,419,420,423,424,427,428,431],{},"Every file has an ",[236,411,238],{},", its key within the drive. ",[236,414,415],{},"client.upload()"," only creates files. An upload with an ",[236,418,238],{}," that the drive already has is refused with code ",[236,421,422],{},"precondition_required",", and nothing is written. The call raises an ",[236,425,426],{},"UploadBatchError"," whose ",[236,429,430],{},"failures"," hold that error:",[255,433,435],{"className":257,"code":434,"language":259,"meta":260,"style":260},"with Flashdrive(drive_id=\"DRIVE_UUID\") as client:\n    client.upload(\"policy-v1.pdf\", external_id=\"refund-policy\")\n    client.upload(\"policy-v2.pdf\", external_id=\"refund-policy\")   # refused: precondition_required\n",[236,436,437,441,446],{"__ignoreMap":260},[264,438,439],{"class":266,"line":267},[264,440,283],{},[264,442,443],{"class":266,"line":273},[264,444,445],{},"    client.upload(\"policy-v1.pdf\", external_id=\"refund-policy\")\n",[264,447,448],{"class":266,"line":280},[264,449,450],{},"    client.upload(\"policy-v2.pdf\", external_id=\"refund-policy\")   # refused: precondition_required\n",[229,452,453,454,457],{},"To put new contents in the file, read it and call ",[236,455,456],{},"documents.replace_file()"," with the revision you read, as shown above.",[250,459,461],{"id":460},"keep-labels-and-location","Keep labels and location",[229,463,464,466,467,471,472,475,476,479],{},[236,465,456],{}," copies the file's metadata and folder to the new contents. A replacement sent straight to the ",[245,468,470],{"href":469},"\u002Freference\u002Fuploads-api#replace-a-specific-revision","uploads API"," does not: its ",[236,473,474],{},"metadata"," replaces all of the file's metadata, and leaving ",[236,477,478],{},"folder_id"," out puts the file at the top of the drive. Send every label and the folder you want to keep.",[229,481,482,483,486,487,490,491,494,495,248],{},"Metadata is a flat object whose values are strings, numbers, booleans or null. PDF, DOCX, TXT and Markdown files take up to 64 fields and 8,000 bytes. Files stored with format ",[236,484,485],{},"file"," take up to 40 fields and 6,000 bytes, plus an optional ",[236,488,489],{},"title"," (up to 500 bytes) and ",[236,492,493],{},"tags"," (up to 32 strings of up to 64 bytes each). Metadata outside these limits is refused with code ",[236,496,497],{},"invalid_metadata",[250,499,501],{"id":500},"replace-text-added-through-the-api","Replace text added through the API",[229,503,504,505,508],{},"For a document your application added as text through the ",[245,506,507],{"href":197},"content API",", replace the whole text:",[255,510,512],{"className":257,"code":511,"language":259,"meta":260,"style":260},"observed = client.documents.get(\"DOCUMENT_UUID\")\nreceipt = client.documents.replace_text(\n    \"DOCUMENT_UUID\",\n    edited_text,\n    expected_revision=observed.latest_revision,\n    idempotency_key=\"save-report-1\",\n)\nprint(receipt.operation_id)\n",[236,513,514,519,524,529,534,539,544,549],{"__ignoreMap":260},[264,515,516],{"class":266,"line":267},[264,517,518],{},"observed = client.documents.get(\"DOCUMENT_UUID\")\n",[264,520,521],{"class":266,"line":273},[264,522,523],{},"receipt = client.documents.replace_text(\n",[264,525,526],{"class":266,"line":280},[264,527,528],{},"    \"DOCUMENT_UUID\",\n",[264,530,531],{"class":266,"line":286},[264,532,533],{},"    edited_text,\n",[264,535,536],{"class":266,"line":292},[264,537,538],{},"    expected_revision=observed.latest_revision,\n",[264,540,541],{"class":266,"line":298},[264,542,543],{},"    idempotency_key=\"save-report-1\",\n",[264,545,546],{"class":266,"line":304},[264,547,548],{},")\n",[264,550,551],{"class":266,"line":310},[264,552,553],{},"print(receipt.operation_id)\n",[229,555,556,559,560,563,564,567,568,571,572,248],{},[236,557,558],{},"documents.replace_text(document_id, text, *, expected_revision, idempotency_key=None)"," takes 1 to 2,000,000 UTF-8 bytes of text and keeps the document's metadata and folder. It returns a ",[236,561,562],{},"MutationReceipt","; follow its ",[236,565,566],{},"operation_id"," with ",[236,569,570],{},"client.operations.get(receipt.operation_id)",". For uploaded text files, use ",[245,573,574],{"href":102},[236,575,576],{},"files.edit_text",[250,578,580],{"id":579},"delete-a-file","Delete a file",[255,582,584],{"className":257,"code":583,"language":259,"meta":260,"style":260},"observed = client.documents.get(\"DOCUMENT_UUID\")\nclient.documents.delete(\n    \"DOCUMENT_UUID\",\n    expected_revision=observed.latest_revision,\n    idempotency_key=\"delete-old-policy-1\",\n)\n",[236,585,586,590,595,599,603,608],{"__ignoreMap":260},[264,587,588],{"class":266,"line":267},[264,589,518],{},[264,591,592],{"class":266,"line":273},[264,593,594],{},"client.documents.delete(\n",[264,596,597],{"class":266,"line":280},[264,598,528],{},[264,600,601],{"class":266,"line":286},[264,602,538],{},[264,604,605],{"class":266,"line":292},[264,606,607],{},"    idempotency_key=\"delete-old-policy-1\",\n",[264,609,610],{"class":266,"line":298},[264,611,548],{},[229,613,614,617,618,620,621,623,624,626,627,248],{},[236,615,616],{},"documents.delete(document_id, *, expected_revision, idempotency_key=None)"," returns a ",[236,619,562],{},". As with replacement, ",[236,622,365],{}," is required and a changed file raises ",[236,625,401],{},". A deleted file stays in the trash for one hour. To delete a folder with everything in it, see ",[245,628,629],{"href":106},"folders",[631,632,634],"h3",{"id":633},"delete-many-files-at-once","Delete many files at once",[255,636,638],{"className":257,"code":637,"language":259,"meta":260,"style":260},"client.documents.delete_many(\n    [{\"id\": \"DOCUMENT_UUID\", \"expected_revision\": observed.latest_revision},\n     (\"OTHER_UUID\", \"REVISION\")],\n    idempotency_key=\"clean-up-1\",\n)\n",[236,639,640,645,650,655,660],{"__ignoreMap":260},[264,641,642],{"class":266,"line":267},[264,643,644],{},"client.documents.delete_many(\n",[264,646,647],{"class":266,"line":273},[264,648,649],{},"    [{\"id\": \"DOCUMENT_UUID\", \"expected_revision\": observed.latest_revision},\n",[264,651,652],{"class":266,"line":280},[264,653,654],{},"     (\"OTHER_UUID\", \"REVISION\")],\n",[264,656,657],{"class":266,"line":286},[264,658,659],{},"    idempotency_key=\"clean-up-1\",\n",[264,661,662],{"class":266,"line":292},[264,663,548],{},[229,665,666,669,670,673,674,677,678,680,681,683,684,687],{},[236,667,668],{},"documents.delete_many(documents, *, idempotency_key=None)"," deletes up to 1,000 files in one request, all or none. Each entry is an ",[236,671,672],{},"{\"id\", \"expected_revision\"}"," dictionary or an ",[236,675,676],{},"(id, revision)"," pair, with the revision you read. A file that is missing, already deleted or at another revision refuses the whole request (",[236,679,401],{}," for a revision), and nothing is deleted. The files go to the trash together. The returned ",[236,682,562],{}," lists each file with the revision the delete left it at. Reuse ",[236,685,686],{},"idempotency_key"," with the same files to retry.",[250,689,691],{"id":690},"read-a-files-details","Read a file's details",[229,693,694,617,697,700,701,704,705,708,709,711,712,382,715,382,717,382,720,382,723,382,726,382,728,382,730,382,732,382,735,382,738,382,741,382,744,746,747,750,751,754],{},[236,695,696],{},"documents.get(document_id)",[236,698,699],{},"Document",", and ",[236,702,703],{},"documents.list(folder_id=None)"," a list of them; ",[236,706,707],{},"folder_id=\"root\""," lists the files outside folders. A ",[236,710,699],{}," has ",[236,713,714],{},"id",[236,716,238],{},[236,718,719],{},"filename",[236,721,722],{},"source_format",[236,724,725],{},"source_bytes",[236,727,369],{},[236,729,478],{},[236,731,474],{},[236,733,734],{},"text_status",[236,736,737],{},"text_status_reason",[236,739,740],{},"created_at",[236,742,743],{},"updated_at",[236,745,566],{}," and ",[236,748,749],{},"operation_state",". Each call takes ",[236,752,753],{},"drive_id"," to override the client's drive.",[250,756,758],{"id":757},"retry-or-make-another-change","Retry or make another change",[229,760,761,762,746,765,248],{},"To retry a replacement whose reply was lost, repeat it with the same idempotency key, file, revision and options. For another change, read the file again and use a new key. Request keys last 24 hours. See ",[245,763,764],{"href":118},"upload recovery",[245,766,767],{"href":126},"errors and retries",[229,769,770,746,773,776,777,780],{},[236,771,772],{},"Flashdrive",[236,774,775],{},"AsyncFlashdrive"," have the same methods; ",[236,778,779],{},"await"," each call with the async client.",[782,783,784],"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":260,"searchDepth":273,"depth":273,"links":786},[787,788,789,790,791,794,795],{"id":252,"depth":273,"text":253},{"id":405,"depth":273,"text":406},{"id":460,"depth":273,"text":461},{"id":500,"depth":273,"text":501},{"id":579,"depth":273,"text":580,"children":792},[793],{"id":633,"depth":280,"text":634},{"id":690,"depth":273,"text":691},{"id":757,"depth":273,"text":758},"Replace a file's contents, keep its identity and labels, and delete files safely.","md",null,{},{"title":113},{"title":113,"description":796},"LA9KXmjC4UyrEh4slVZstEEHJ9wFpPbmFyLU9Lv9-bY",[804,806],{"title":109,"path":110,"stem":111,"description":805,"children":-1},"Create drives, choose where client calls run, and give a sandbox one drive.",{"title":117,"path":118,"stem":119,"description":807,"children":-1},"Resume accepted work and keep the files that succeeded.",1795366546182]