Skip to content

Add Hugging Face Provider - #76317

Merged
kaxil merged 39 commits into
apache:mainfrom
ParagEkbote:add-airflow-hf-provider
Nov 11, 2026
Merged

kaxil merged 39 commits into
apache:mainfrom
ParagEkbote:add-airflow-hf-provider

Conversation

@ParagEkbote

@ParagEkbote ParagEkbote commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Based on the following ASF discuss thread, this PR adds the HF Provider for Apache Airflow. The following tasks need to be completed along with the reviewer comments:

  • Build the provider docs with breeze
  • Wire in the system tests with the HF token/secret from the HF org

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Codex


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@dabla

dabla commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for this, nice to see a Hugging Face provider coming in!

One suggestion for the hook: add native async variants of the metadata calls, so they can be used from async tasks and triggers without blocking the event loop. Deferrable operators aren't needed for this, async methods on the hook are enough.

HfApi itself is sync only, but huggingface_hub already ships what's needed: huggingface_hub.utils.get_async_session() returns the configured httpx.AsyncClient that AsyncInferenceClient uses, and the Hub endpoints behind the current methods are plain REST calls:

Hook method HfApi call Endpoint
get_dataset_info dataset_info GET /api/datasets/{repo_id}[/revision/{revision}]
find_commit_by_marker list_repo_refs GET /api/datasets/{repo_id}/refs?include_prs=1
find_commit_by_marker list_repo_commits GET /api/datasets/{repo_id}/commits/{revision} (paginated)

Something along these lines:

from urllib.parse import quote

from huggingface_hub import DatasetInfo, constants
from huggingface_hub.utils import build_hf_headers, get_async_session, hf_raise_for_status

from airflow.providers.common.compat.connection import get_async_connection


async def aget_dataset_info(self, repo_id: str, revision: str | None = None) -> DatasetInfo:
    connection = await get_async_connection(self.huggingface_conn_id, hook=self)
    url = f"{constants.ENDPOINT}/api/datasets/{repo_id}"
    if revision:
        url += f"/revision/{quote(revision, safe='')}"
    async with get_async_session() as client:
        response = await client.get(url, headers=build_hf_headers(token=connection.password))
    hf_raise_for_status(response)
    return DatasetInfo(**response.json())

Two things to watch for:

  • The token has to come from get_async_connection (common.compat): calling the sync get_token() / get_connection() inside a coroutine blocks the event loop and can deadlock on the supervisor channel.
  • Building DatasetInfo / GitCommitInfo from the JSON (as HfApi does internally) keeps the async methods returning the same types as the sync ones, so _commit_is_complete and the marker matching can be shared between both paths.

load_dataset and push_to_hub can stay sync, since datasets has no async API and those are file transfers anyway. When Inference Endpoints are added later, AsyncInferenceClient would give the async side of that for free.

Happy to review if you pick this up, here or in a follow-up PR.

@ParagEkbote

Copy link
Copy Markdown
Contributor Author

Thanks for this, nice to see a Hugging Face provider coming in!

One suggestion for the hook: add native async variants of the metadata calls, so they can be used from async tasks and triggers without blocking the event loop. Deferrable operators aren't needed for this, async methods on the hook are enough.

HfApi itself is sync only, but huggingface_hub already ships what's needed: huggingface_hub.utils.get_async_session() returns the configured httpx.AsyncClient that AsyncInferenceClient uses, and the Hub endpoints behind the current methods are plain REST calls:

Hook method HfApi call Endpoint
get_dataset_info dataset_info GET /api/datasets/{repo_id}[/revision/{revision}]
find_commit_by_marker list_repo_refs GET /api/datasets/{repo_id}/refs?include_prs=1
find_commit_by_marker list_repo_commits GET /api/datasets/{repo_id}/commits/{revision} (paginated)
Something along these lines:

from urllib.parse import quote

from huggingface_hub import DatasetInfo, constants
from huggingface_hub.utils import build_hf_headers, get_async_session, hf_raise_for_status

from airflow.providers.common.compat.connection import get_async_connection


async def aget_dataset_info(self, repo_id: str, revision: str | None = None) -> DatasetInfo:
    connection = await get_async_connection(self.huggingface_conn_id, hook=self)
    url = f"{constants.ENDPOINT}/api/datasets/{repo_id}"
    if revision:
        url += f"/revision/{quote(revision, safe='')}"
    async with get_async_session() as client:
        response = await client.get(url, headers=build_hf_headers(token=connection.password))
    hf_raise_for_status(response)
    return DatasetInfo(**response.json())

Two things to watch for:

  • The token has to come from get_async_connection (common.compat): calling the sync get_token() / get_connection() inside a coroutine blocks the event loop and can deadlock on the supervisor channel.
  • Building DatasetInfo / GitCommitInfo from the JSON (as HfApi does internally) keeps the async methods returning the same types as the sync ones, so _commit_is_complete and the marker matching can be shared between both paths.

load_dataset and push_to_hub can stay sync, since datasets has no async API and those are file transfers anyway. When Inference Endpoints are added later, AsyncInferenceClient would give the async side of that for free.

Happy to review if you pick this up, here or in a follow-up PR.

Thank you for reaching out and for the support. Currently, I would prefer to finalize the HF provider's public API and focus on the features stated in the mailing list. I've created an issue for the requested feature and will certainly ask for your feedback in a follow up PR.

Regards,

Parag Ekbote

@kaxil kaxil self-assigned this Nov 5, 2026
Comment thread providers/huggingface/pyproject.toml Resolved
Comment thread providers/huggingface/pyproject.toml Resolved
Comment thread providers/huggingface/pyproject.toml Resolved
Comment thread providers/huggingface/provider.yaml Resolved
Comment thread pyproject.toml Resolved
Comment thread providers/huggingface/docs/index.rst Resolved
Comment thread providers/huggingface/provider.yaml Resolved
… the doc errors, update the wordlist and add tags for get_provider_info.py
Comment thread providers/huggingface/docs/index.rst Resolved
Comment thread pyproject.toml Resolved
Comment thread uv.lock Resolved
Comment thread providers/huggingface/provider.yaml Resolved
- Keep the split name on zero-row artifact splits, so an empty split is
  not published as `train`.
- Drop the `hf://datasets/<repo>` outlet for pull request and non-main
  pushes in `__init__`, so a mapped task with expanded `push_kwargs` no
  longer emits the repo-level asset event.
- Remove the post-push commit lookups: `push_to_hub` to a dataset repo
  always returns a `CommitInfo` on datasets>=5.0.
- Define `get_ui_field_behaviour` on the hook for Airflow 3.0 and 3.1,
  which do not read `ui-field-behaviour` from provider.yaml.
- Move `asset.py` to `assets/huggingface.py`, drop `tests/__init__.py`
  and `tests/system/README.md`, and hoist the `re` import.
- Use the standard provider changelog template, list `LargeList` in the
  artifact docs, and apply the prek fixes (license headers, ruff,
  pyproject ordering, system test segments).

@kaxil kaxil left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed the remaining fixes on top (empty split label, PR-push outlets on mapped tasks, get_ui_field_behaviour for 3.0/3.1, assets/ move, changelog template, prek). LGTM, thanks @ParagEkbote! The uv.lock downgrade gets a relock in a follow-up once datasets 5.2.0 clears the cooldown.

@kaxil
kaxil enabled auto-merge (squash) November 10, 2026 20:44
@kaxil
kaxil disabled auto-merge November 10, 2026 20:47
@kaxil
kaxil enabled auto-merge (squash) November 10, 2026 20:47
`check-provider-yaml-valid` skips `index.rst` pages when it collects the
expected how-to guides, so a `how-to-guide` entry pointing at
`operators/index.rst` never matches and the static check fails.
`Asset` is not hashable on Airflow 3.0, so the test can't key a dict by
the published asset. Pass an outlet-events object with `__getitem__`, as
the other publication tests in this module do.
@kaxil
kaxil disabled auto-merge November 11, 2026 02:50
@kaxil
kaxil merged commit 4d1bc90 into apache:main Nov 11, 2026
554 of 557 checks passed
@boring-cyborg

boring-cyborg Bot commented Nov 11, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants