Skip to main content

Provider package teserak-airflow-providers-teams for Apache Airflow

Project description

teserak-airflow-providers-teams

Provider package for Microsoft Teams integration with Apache Airflow.

Installation

pip install teserak-airflow-providers-teams

Requirements

  • Apache Airflow >= 2.11.0
  • Python >= 3.10

Connection Setup

Configure an Airflow connection of type teams:

Field Description
Connection Id e.g. teams_default
Connection Type teams
Host (leave empty)
Extra {"webhook_url": "https://...webhook.office.com/..."}

You can also pass the webhook_url directly to the hook/operator without a connection.

Teams uses Incoming Webhooks — create one via:

  • Microsoft Teams: Apps → Incoming Webhooks → configure for a channel
  • Power Automate Workflows (recommended, replaces older Office 365 connectors)

Usage

Hook

from teserak.airflow.providers.teams.hooks.teams_webhook import TeamsWebhookHook
from teserak.airflow.providers.teams.notifications.adaptive_card import (
    AdaptiveCard,
    TextBlock,
    build_success_card,
)

hook = TeamsWebhookHook(
    teams_conn_id="teams_default",
    message="DAG finished successfully!",
)
hook.execute()

# With Adaptive Card
card = build_success_card(
    dag_id="my_dag",
    task_id="my_task",
    execution_date="2024-01-15T10:30:00Z",
    log_url="https://airflow.example.com/log",
)
hook = TeamsWebhookHook(teams_conn_id="teams_default", card=card)
hook.execute()

Operator

from teserak.airflow.providers.teams.operators.teams_webhook import TeamsWebhookOperator

notify = TeamsWebhookOperator(
    task_id="send_teams_message",
    teams_conn_id="teams_default",
    message="Pipeline {{ dag.dag_id }} finished at {{ ts }}",
)

Notifier (on_failure_callback / on_success_callback)

from teserak.airflow.providers.teams.notifications.teams import TeamsNotifier
from teserak.airflow.providers.teams.notifications.adaptive_card import (
    build_failure_card,
    build_success_card,
)

with DAG(
    dag_id="my_pipeline",
    on_failure_callback=TeamsNotifier(
        teams_conn_id="teams_default",
        card=build_failure_card(
            dag_id="my_pipeline",
            log_url="https://airflow.example.com/log",
        ),
    ),
    on_success_callback=TeamsNotifier(
        teams_conn_id="teams_default",
        card=build_success_card(
            dag_id="my_pipeline",
            log_url="https://airflow.example.com/log",
        ),
    ),
):
    ...

You can also use a plain text message instead of a card:

with DAG(
    dag_id="my_pipeline",
    on_failure_callback=TeamsNotifier(
        teams_conn_id="teams_default",
        text="DAG {{ dag.dag_id }} failed at {{ ts }}!",
    ),
):
    ...

Ready-made Success / Failure Cards

from teserak.airflow.providers.teams.notifications.adaptive_card import (
    build_success_card,
    build_failure_card,
)

# Success card — green header, checkmark, facts with DAG/task/time/log URL
success_card = build_success_card(
    dag_id="my_dag",
    task_id="my_task",
    execution_date="2024-01-15T10:30:00Z",
    log_url="https://airflow.example.com/log",
)

# Failure card — red header, cross, exception details
failure_card = build_failure_card(
    dag_id="my_dag",
    task_id="my_task",
    execution_date="2024-01-15T10:30:00Z",
    exception="ValueError: unexpected value",
    log_url="https://airflow.example.com/log",
)

Adaptive Card Structure

Teams uses Adaptive Cards instead of Discord's Embed objects. All types are fully typed as TypedDict:

  • AdaptiveCard — root card (body, actions, $schema, version)
  • TextBlock — text elements with size/weight/color/wrap
  • FactSet / Fact — key-value pairs (analogous to Discord EmbedField)
  • Image — image element
  • ColumnSet / Column — multi-column layout
  • Container — grouping container with optional background
  • ActionOpenUrl / ActionSet — clickable button actions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

teserak_airflow_providers_teams-1.0.0.tar.gz (241.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file teserak_airflow_providers_teams-1.0.0.tar.gz.

File metadata

File hashes

Hashes for teserak_airflow_providers_teams-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cb5510988551b0ba6bc19353630f384111d8fe67a187bda8260cc37e972201b7
MD5 09182f7bd930b622991f570fc93e4cf1
BLAKE2b-256 5340990f01b4b235aebb0b6b6628c0678c4609e517631f9b4f5e8be6947844f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for teserak_airflow_providers_teams-1.0.0.tar.gz:

Publisher: release.yml on teserak/airflow-teams

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file teserak_airflow_providers_teams-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for teserak_airflow_providers_teams-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cce0f71d0ea087d2ac810b6b042f42bea913bba3973f15f211762a76851be4dd
MD5 5695310838f264c1f96bedadabff533a
BLAKE2b-256 8096bd37223f3a915f496ba89a209529e3534eb63affbd56b34e167c55f72b02

See more details on using hashes here.

Provenance

The following attestation bundles were made for teserak_airflow_providers_teams-1.0.0-py3-none-any.whl:

Publisher: release.yml on teserak/airflow-teams

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page