Skip to content

Add native async variants of the metadata call for HF Provider #76470

Open

Description

@ParagEkbote

Description

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.

Originally posted by @dabla in #76317 (comment)

Use case/motivation

No response

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:feature
    needs-triage
    on Nov 4, 2026
  2. Priyeshshrivastav commented on Nov 5, 2026

    @Priyeshshrivastav

    Hi @ParagEkbote,

    I went through the issue and your ongoing Hugging Face provider PR.

    I'd be interested in contributing to the async metadata methods once the provider's public API is finalized.

    I have experience with Python, async programming, backend development, and API integration. I'd be happy to help implement aget_dataset_info() and afind_commit_by_marker(), along with tests ensuring compatibility with the existing synchronous methods.

    Please let me know when this work is ready for community contributions. I'd be glad to help!

    Thanks!

  3. ParagEkbote commented on Nov 12, 2026

    @ParagEkbote
    ContributorAuthor

    Hi @ParagEkbote,

    I went through the issue and your ongoing Hugging Face provider PR.

    I'd be interested in contributing to the async metadata methods once the provider's public API is finalized.

    I have experience with Python, async programming, backend development, and API integration. I'd be happy to help implement aget_dataset_info() and afind_commit_by_marker(), along with tests ensuring compatibility with the existing synchronous methods.

    Please let me know when this work is ready for community contributions. I'd be glad to help!

    Thanks!

    Thanks for your interest in contributing for the hf provider. The provider is now open for community contributions

    A few things to keep in mind before opening the PR:

    1. ASF contribution guidelines: Please follow the Apache Airflow contributing guidelines including the project's coding conventions, testing requirements, licensing expectations and Code of Conduct.

    2. AI-assisted development: If you use AI coding tools, please follow the ASF Generative Tooling Guidance. In particular, ensure that you understand and have personally reviewed all submitted code.

    Please open a PR against the Apache Airflow repository and link it to this issue

    Regards,

    Parag Ekbote

  4. Anurag-S1ngh commented on Nov 14, 2026

    @Anurag-S1ngh
    Contributor

    Hi, I'm working on this. I'll add async variants of the metadata calls (aget_dataset_info, afind_commit_by_marker) with tests.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:featureneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions