-
Notifications
You must be signed in to change notification settings - Fork 437
docs: add "Access Buckets from Code" page #2363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
davanstrien
wants to merge
4
commits into
main
Choose a base branch
from
docs/buckets-access-patterns
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+73
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e146b9
Add "Access Buckets from Code" docs page
davanstrien 7bb0d52
Rename buckets page from "Access Buckets from Code" to "Access Patterns"
davanstrien f63cfcf
Add link to Spaces volume mount guide from access patterns page
davanstrien 8e59e8d
Group volume mounts with hf-mount in Access Patterns
davanstrien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Access Patterns | ||
|
|
||
| Beyond the [CLI and Python SDK](./storage-buckets#managing-files), there are several ways to access bucket data from your existing tools and workflows. | ||
|
|
||
| ## Choosing an Access Method | ||
|
|
||
| | Method | Best for | Details | | ||
| |--------|----------|---------| | ||
| | **hf-mount** | Mount as local filesystem — any tool works | [See below](#mount-as-a-local-filesystem) | | ||
| | **Volume mounts** | HF Jobs & Spaces (same idea, managed for you) | [See below](#volume-mounts-in-jobs-and-spaces) | | ||
| | **hf:// paths** (fsspec) | Python data tools (pandas, DuckDB) | [See below](#python-data-tools) | | ||
| | **CLI sync** | Batch transfers, backups | [Sync docs](./storage-buckets#syncing-directories) | | ||
|
|
||
| ## Mount as a Local Filesystem | ||
|
|
||
| [hf-mount](https://github.com/huggingface/hf-mount) lets you mount buckets (and repos) as local filesystems via NFS (recommended) or FUSE. Files are fetched lazily — only the bytes your code reads hit the network. | ||
|
|
||
| Install: | ||
|
|
||
| ```bash | ||
| curl -fsSL https://raw.githubusercontent.com/huggingface/hf-mount/main/install.sh | sh | ||
| ``` | ||
|
|
||
| Mount a bucket: | ||
|
|
||
| ```bash | ||
| hf-mount start bucket username/my-bucket /mnt/data | ||
| ``` | ||
|
|
||
| Once mounted, any tool that reads or writes files works with your bucket — pandas, DuckDB, vLLM, training scripts, shell commands, etc. | ||
|
|
||
| > [!TIP] | ||
| > Buckets are mounted read-write; repos are read-only. See the [hf-mount repository](https://github.com/huggingface/hf-mount) for full documentation including backend options, caching, and write modes. | ||
|
|
||
| ## Volume Mounts in Jobs and Spaces | ||
|
|
||
| Volume mounts in [Jobs](./jobs) and [Spaces](./spaces) are the same idea as `hf-mount`, managed for you by the platform — no extra setup needed. Buckets are mounted read-write by default. | ||
|
|
||
| ```bash | ||
| hf jobs run -v hf://buckets/username/my-bucket:/data python:3.12 python script.py | ||
| ``` | ||
|
|
||
| For the full volume mount syntax and Python API, see the [Jobs configuration docs](./jobs-configuration#volumes) and the [Spaces volume mount guide](/docs/huggingface_hub/guides/manage-spaces#mount-volumes-in-your-space). | ||
|
|
||
| ## Python Data Tools | ||
|
|
||
| The [`HfFileSystem`](/docs/huggingface_hub/guides/hf_file_system) provides [fsspec](https://filesystem-spec.readthedocs.io)-compatible access to buckets using `hf://buckets/` paths. Any Python library that supports fsspec can read and write bucket data directly. | ||
|
|
||
| **pandas:** | ||
|
|
||
| ```python | ||
| import pandas as pd | ||
|
|
||
| df = pd.read_parquet("hf://buckets/username/my-bucket/data.parquet") | ||
| df.to_parquet("hf://buckets/username/my-bucket/output.parquet") | ||
| ``` | ||
|
|
||
| **DuckDB** (Python client): | ||
|
|
||
| ```python | ||
| import duckdb | ||
| from huggingface_hub import HfFileSystem | ||
|
|
||
| duckdb.register_filesystem(HfFileSystem()) | ||
| duckdb.sql("SELECT * FROM 'hf://buckets/username/my-bucket/data.parquet' LIMIT 10") | ||
| ``` | ||
|
|
||
| For more on `hf://` paths and supported operations, see the [`HfFileSystem` guide](/docs/huggingface_hub/guides/hf_file_system) and the [Buckets Python guide](/docs/huggingface_hub/guides/buckets). | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really need to submit it to brew