# Login with huggingface-cli login
df.write.format("huggingface").mode("overwrite").save("username/my_dataset")
# Or pass a token manually
df.write.format("huggingface").option("token", "hf_xxx").mode("overwrite").save("username/my_dataset")
Hugging Face uses Xet: a dedupe-based storage which enables fast deduped uploads.
Unlike traditional remote storage, uploads are faster on Xet because duplicate data is only uploaded once.
For example: if some or all of the data already exists in other files on Xet, it is not uploaded again, saving bandwidth and speeding up uploads. Deduplication for Parquet is enabled through Content Defined Chunking (CDC).
Thanks to Parquet CDC and Xet deduplication, saving a dataset on Hugging Face is faster than on any traditional remote storage.
While the Data Source API was introcuded in Spark 4, this package includes a backport for older versions.
Importing pyspark_huggingface patches the PySpark reader and writer to add the "huggingface" data source. It is compatible with PySpark 3.5, 3.4 and 3.3:
>>> import pyspark_huggingface
huggingface datasource enabled for pyspark 3.x.x (backport from pyspark 4)
The import is only necessary on Spark 3.x to enable the backport.
Spark 4 automatically imports pyspark_huggingface as soon as it is installed, and registers the "huggingface" data source.