Today, we're announcing swift-huggingface, a latest Swift package that provides a complete client for the Hugging Face Hub.

You can start using it today as a standalone package, and it will soon integrate into swift-transformers as a replacement for its current HubApi implementation. (Related: Fine-Tune XLSR-Wav2Vec2 for low-resource ASR with 🤗 Tra...)

When we released swift-transformers 1.0 earlier this year, we heard loud and clear from the community:. (Related: Accelerating PyTorch Transformers with Intel Sapphire R...)

According to recent reports, swift-huggingface is a ground-up rewrite focused on reliability and developer experience. It provides:.

According to recent reports, one of the biggest improvements is how authentication works. The TokenProvider pattern makes it explicit where credentials come from:.

The auto-detection follows the same conventions as the Python huggingface_hub library:.

This means if you've already logged in with hf auth login, swift-huggingface will automatically find and use that token.

According to recent reports, building an app where users sign in with their Hugging Face account? swift-huggingface includes a complete OAuth 2.0 implementation:.

The OAuth manager handles token storage in Keychain, automatic refresh, and secure sign-out. No more manual token management.

Downloading large models is now straightforward with proper progress tracking and resume support:.

If a download is interrupted, you can resume it:.

For downloading entire model repositories, downloadSnapshot handles everything:.

The snapshot function tracks metadata for each file, so subsequent calls only download files that have changed.

In a recent development, remember the second problem we mentioned? "No shared cache with the Python ecosystem." That's now solved.

swift-huggingface implements a Python-compatible cache structure that allows seamless sharing between Swift and Python clients:.

The cache location follows the same environment variable conventions as Python:.

You can also use the cache directly:.

To prevent race conditions when multiple processes access the same cache, swift-huggingface uses file locking (flock(2)).

Here's what downloading a model snapshot looked like with the old HubApi:.

And here's the same operation with swift-huggingface:.

The API is similar, but the implementation is completely different — built on URLSession download tasks with proper delegate handling, resume data support, and metadata tracking.

Recent findings suggest that but wait, there's more! swift-huggingface contains a complete Hub client:.

Recent findings suggest that and that's not all! swift-huggingface has everything you need to interact with Hugging Face Inference Providers, giving your app instant access to hundreds of machine learning models, powered by world-class inference providers:.

Check the README for a full list of everything that's supported.

We're actively working on two fronts:.

Industry observers note that integration with swift-transformers. We have a pull request in progress to replace HubApi with swift-huggingface. This will bring reliable downloads to everyone using swift-transformers, mlx-swift-lm, and the broader ecosystem. If you maintain a Swift-based library or app and want help adopting swift-huggingface, reach out — we're happy to help.

Recent findings suggest that faster downloads with Xet. We're adding support for the Xet storage backend, which enables chunk-based deduplication and significantly faster downloads for large models. More on this soon.

Add swift-huggingface to your project:.

Recent findings suggest that we'd love your feedback. If you've been frustrated with model downloads in Swift, give this a try and let us know how it goes. Your experience reports will help us prioritize what to improve next.

Sources indicate that thanks to the swift-transformers community for the feedback that shaped this project, and to everyone who filed issues and shared their experiences. This is for you. ❤️.

→ Read original article