Apache Airflow provider package for seamless GitHub integration through hooks, operators, and sensors
npx @tessl/cli install tessl/pypi-apache-airflow-providers-github@2.9.0Apache Airflow provider package for seamless GitHub integration through hooks, operators, and sensors. Enables GitHub repository management, issue tracking, pull request automation, and workflow orchestration within Apache Airflow DAGs using the PyGithub SDK.
pip install apache-airflow-providers-githubapache-airflow>=2.10.0, PyGithub>=2.1.1from airflow.providers.github.hooks.github import GithubHook
from airflow.providers.github.operators.github import GithubOperator
from airflow.providers.github.sensors.github import GithubSensor, GithubTagSensor, BaseGithubRepositorySensor
from airflow.providers.github.get_provider_info import get_provider_info
from airflow.providers.github import __version__from datetime import datetime
from airflow import DAG
from airflow.providers.github.hooks.github import GithubHook
from airflow.providers.github.operators.github import GithubOperator
from airflow.providers.github.sensors.github import GithubTagSensor
# Create a DAG
dag = DAG(
'github_example',
start_date=datetime(2024, 1, 1),
schedule_interval='@daily',
catchup=False
)
# Use the hook to connect to GitHub
hook = GithubHook(github_conn_id='github_default')
client = hook.get_conn()
user = client.get_user()
# Use an operator to list repositories
list_repos = GithubOperator(
task_id='list_repositories',
github_method='get_user',
result_processor=lambda user: [repo.name for repo in user.get_repos()],
dag=dag
)
# Use a sensor to monitor for a tag
wait_for_tag = GithubTagSensor(
task_id='wait_for_v1_release',
repository_name='apache/airflow',
tag_name='v1.0',
timeout=300,
dag=dag
)The GitHub provider follows Apache Airflow's standard provider architecture:
All components use PyGithub as the underlying GitHub SDK and follow Airflow's templating, logging, and error handling patterns.
Establishes and manages authenticated connections to GitHub API using tokens, with support for GitHub Enterprise through custom base URLs.
class GithubHook(BaseHook):
def __init__(self, github_conn_id: str = "github_default", *args, **kwargs) -> None: ...
def get_conn(self) -> GithubClient: ...
def test_connection(self) -> tuple[bool, str]: ...Execute arbitrary GitHub API operations through PyGithub methods, with support for result processing and templated parameters.
class GithubOperator(BaseOperator):
def __init__(
self,
*,
github_method: str,
github_conn_id: str = "github_default",
github_method_args: dict | None = None,
result_processor: Callable | None = None,
**kwargs,
) -> None: ...
def execute(self, context: Context) -> Any: ...Monitor GitHub resources for changes and trigger downstream tasks based on repository events, tag creation, or custom conditions.
class GithubSensor(BaseSensorOperator):
def __init__(
self,
*,
method_name: str,
github_conn_id: str = "github_default",
method_params: dict | None = None,
result_processor: Callable | None = None,
**kwargs,
) -> None: ...
def poke(self, context: Context) -> bool: ...
class GithubTagSensor(BaseGithubRepositorySensor):
def __init__(
self,
*,
github_conn_id: str = "github_default",
tag_name: str | None = None,
repository_name: str | None = None,
**kwargs,
) -> None: ...
def poke(self, context: Context) -> bool: ...Access provider information and registration details through the provider info function.
def get_provider_info() -> dict:
"""
Return provider metadata dictionary.
Returns comprehensive provider information including hooks, operators,
sensors, and connection types for Airflow provider registration.
Returns:
dict: Provider metadata with integration details
"""Configure GitHub connections in Airflow:
githubgithub_default (default)https://{hostname}/api/v3)from typing import Any, TYPE_CHECKING
from collections.abc import Callable
from github import Github as GithubClient, GithubException
from airflow.exceptions import AirflowException
from airflow.providers.github.version_compat import (
Context, BaseHook, BaseOperator, BaseSensorOperator,
AIRFLOW_V_3_0_PLUS, AIRFLOW_V_3_1_PLUS
)
# Type aliases used throughout the package
Context = Context # Airflow execution context
GithubClient = GithubClient # PyGithub client instance
# Exception types
GithubException = GithubException # PyGithub API exceptions
AirflowException = AirflowException # Airflow framework exceptions
# Version-compatible base classes
BaseHook = BaseHook # Base hook class (version-dependent import)
BaseOperator = BaseOperator # Base operator class (version-dependent import)
BaseSensorOperator = BaseSensorOperator # Base sensor class (version-dependent import)
# Version detection constants
AIRFLOW_V_3_0_PLUS = AIRFLOW_V_3_0_PLUS # Boolean for Airflow 3.0+ compatibility
AIRFLOW_V_3_1_PLUS = AIRFLOW_V_3_1_PLUS # Boolean for Airflow 3.1+ compatibility
# Package version
__version__ = "2.9.2" # Package version string