Skip to main content

Crate xet

Crate xet 

Source
Expand description

Rust client library for the Hugging Face Xet storage system.

Xet is the storage backend used by the Hugging Face Hub for large files. Files are split into variable-size chunks, deduplicated, and stored in CAS (Content-Addressed Storage) server. This crate provides a high-level API for uploading and downloading those files.

§Getting started

All operations go through xet_session::XetSession, which manages a tokio runtime and shared HTTP settings. Create one with XetSessionBuilder, then use it to build upload commits or download groups:

use xet::xet_session::{Sha256Policy, XetFileInfo, XetSessionBuilder};

let session = XetSessionBuilder::new().build()?;

// Upload a file
let commit = session
    .new_upload_commit()?
    .with_endpoint("https://cas.example.com")
    .with_token_info("write-token", 1_700_000_000)
    .build_blocking()?;
let handle = commit.upload_from_path_blocking("file.bin".into(), Sha256Policy::Compute)?;
let report = commit.commit_blocking()?;

// Download a file using the metadata from the upload
let meta = report.uploads.values().next().unwrap();
let group = session
    .new_file_download_group()?
    .with_token_info("read-token", 1_700_000_000)
    .build_blocking()?;
group.download_file_to_path_blocking(meta.xet_info.clone(), "out/file.bin".into())?;
group.finish_blocking()?;

See the xet_session module for the full API, including async variants, streaming uploads and downloads, and progress tracking.

§Modules

  • xet_session — the primary API: XetSession, upload commits, file download groups, and streaming downloads.
  • errorXetError, the unified error type for the public API.

Re-exports§

pub use error::XetError;

Modules§

error
legacy
Legacy helpers re-exported for backward compatibility.
xet_session
Session-based file upload and download API for XetHub / HuggingFace Hub.