feat: add low-level storage buckets API#20
Open
jgodlew wants to merge 6 commits intohuggingface:mainfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
HFBucket— Storage Buckets API clientImplements the HuggingFace Storage Buckets low-level API as a typed async Rust client, following the same handle pattern as
HFRepositoryandHFSpace.Scope
The
HFBucketclient struct interface is a low-level wrapper around the bucket APIs exposed by huggingface hub. It currently doesn't provide any higher-level functionality (such as high-level download, upload, or sync APIs). Those APIs might be added later on to provide parity with the huggingface_hub python library if needed. Because of this, this API is not documented in the README.md, nor exposed in the hfrs cli application.What's new
HFBuckethandle (client.bucket(namespace, repo))get()delete()update_settings(params)batch_files(ops)list_tree(path, params)get_paths_info(paths)get_xet_write_token()get_xet_read_token()resolve_file(path)X-Linked-Size,X-XET-Hash,Link)xet_resolve_file(path)(feature =xet)XetFileInforeconstruction metadataHFClientmethodsclient.bucket(namespace, repo)— create a bucket handle (no I/O)client.create_bucket(namespace, repo, params)— create a new bucketclient.list_buckets(namespace)— paginated stream ofBucketOverviewHFBucketSync(feature =blocking)Blocking wrappers for all of the above.
list_treeandlist_bucketscollect intoVec.Error handling
Three new
HFErrorvariants to cover bucket-specific HTTP status codes:Forbidden(403)Conflict(String)(409) — carries the response bodyRateLimited(429)A private
check_bucket_responsehelper inapi/buckets.rsmaps these uniformly across all bucket endpoints.New types (
types/buckets.rs)BucketInfo,BucketOverview,BucketCreated,CdnRegion,ResourceGroup,XetToken,PathInfo,TreeEntry,EntryType,BatchOp,AddFileOp,DeleteFileOp,BatchResult,BatchFailure,ResolvedFile,CreateBucketParams,UpdateBucketParams,ListTreeParams,XetFileInfo(feature =xet)Tests
integration_test.rsthat skip gracefully withoutHF_TOKEN; write tests also requireHF_TEST_WRITE=1test_list_bucketstest_create_and_delete_bucket— full create → get → update → delete → confirm-gone lifecycletest_bucket_list_tree_emptytest_get_xet_write_and_read_token