{"id":6516,"library":"apache-airflow-providers-sendgrid","title":"Apache Airflow SendGrid Provider","description":"The `apache-airflow-providers-sendgrid` package integrates Apache Airflow with SendGrid, a popular email delivery service, allowing users to send emails programmatically from Airflow DAGs. It includes operators and hooks to interact with the SendGrid API. The provider is actively maintained, with version 4.2.2 being the latest, and releases frequently in alignment with Apache Airflow's provider release cycle.","status":"active","version":"4.2.2","language":"en","source_language":"en","source_url":"https://github.com/apache/airflow/tree/main/airflow/providers/sendgrid","tags":["airflow","sendgrid","email","provider","apache"],"install":[{"cmd":"pip install apache-airflow-providers-sendgrid","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core Apache Airflow library; required for provider functionality.","package":"apache-airflow","version":">=2.11.0"},{"reason":"Official SendGrid Python SDK.","package":"sendgrid","version":">=6.12.3; python_version < \"3.12\"","optional":false},{"reason":"Official SendGrid Python SDK.","package":"sendgrid","version":">=6.0.0,<6.12.3; python_version >= \"3.12\"","optional":false},{"reason":"Provides compatibility utilities across different Airflow provider versions.","package":"apache-airflow-providers-common-compat","version":">=1.8.0","optional":false},{"reason":"HTTP utility library; specific versions required for certain Python versions.","package":"werkzeug","version":">=2.2,<4; python_version >= \"3.12\" and python_version <= \"3.13\"","optional":false},{"reason":"HTTP utility library; specific versions required for certain Python versions.","package":"werkzeug","version":">=3.1.6,<4; python_version >= \"3.14\"","optional":false}],"imports":[{"symbol":"SendGridOperator","correct":"from airflow.providers.sendgrid.operators.sendgrid import SendGridOperator"},{"symbol":"SendGridHook","correct":"from airflow.providers.sendgrid.hooks.sendgrid import SendGridHook"}],"quickstart":{"code":"import os\nfrom datetime import datetime\n\nfrom airflow import DAG\nfrom airflow.providers.sendgrid.operators.sendgrid import SendGridOperator\n\n# Ensure you have a SendGrid API Key configured in Airflow Connections\n# named 'sendgrid_default'. For a quick start, you can set an environment variable:\n# export AIRFLOW_CONN_SENDGRID_DEFAULT='sendgrid://:YOUR_SENDGRID_API_KEY@'\n# Replace 'YOUR_SENDGRID_API_KEY' with your actual key (starting with SG.)\n\nwith DAG(\n    dag_id='sendgrid_email_example',\n    start_date=datetime(2023, 1, 1),\n    schedule_interval=None,\n    catchup=False,\n    tags=['sendgrid', 'email'],\n) as dag:\n    send_email_task = SendGridOperator(\n        task_id='send_test_email',\n        sendgrid_conn_id='sendgrid_default',\n        to='recipient@example.com', # Replace with actual recipient\n        subject='Airflow SendGrid Test Email',\n        html_content='<strong>This is a test email from Airflow via SendGrid!</strong>',\n        from_email='sender@example.com', # Replace with actual sender (verified in SendGrid)\n    )\n","lang":"python","description":"This quickstart DAG demonstrates how to use the `SendGridOperator` to send an email. It assumes a SendGrid connection named `sendgrid_default` is configured in Airflow. For local testing, you can set the connection via an environment variable `AIRFLOW_CONN_SENDGRID_DEFAULT` using your SendGrid API Key."},"warnings":[{"fix":"Always check the `apache-airflow-providers-sendgrid` PyPI page or documentation for the exact `apache-airflow` version requirement compatible with your provider version before installation. Upgrade Airflow if necessary (e.g., `pip install 'apache-airflow[cncf.kubernetes,celery]==X.Y.Z' --constraint ...`).","message":"Provider version compatibility with Apache Airflow: Different provider versions require specific minimum Airflow versions. Installing a provider version incompatible with your Airflow setup might lead to automatic Airflow upgrades or `ModuleNotFoundError` if dependencies are not met. For example, provider 4.2.2 requires Airflow >= 2.11.0, while 3.0.0 required Airflow >= 2.2.0.","severity":"breaking","affected_versions":"All versions"},{"fix":"Use Airflow Connections (either via UI or environment variable `AIRFLOW_CONN_SENDGRID_DEFAULT`) to store your SendGrid API key. Place the API key (e.g., `SG.xyz...`) in the 'Password' field of the connection. The connection ID is typically `sendgrid_default`. Example environment variable: `export AIRFLOW_CONN_SENDGRID_DEFAULT='sendgrid://:YOUR_API_KEY@'`","message":"Fetching SendGrid credentials from environment variables (e.g., `SENDGRID_API_KEY`) directly is deprecated. It's recommended to configure SendGrid connections via Airflow's connection mechanism for better security and management.","severity":"deprecated","affected_versions":"1.0.1 and later"},{"fix":"Ensure your Airflow installation is up-to-date (Airflow 2.2.0+ is recommended). If the issue persists, create the connection programmatically via the Airflow CLI or environment variables, or restart Airflow components. Make sure to use `Conn Type: SendGrid` in the UI if available.","message":"SendGrid connection type might not appear in the Airflow UI dropdown for older Airflow versions or if the provider is not correctly registered. This can lead to confusion when setting up connections.","severity":"gotcha","affected_versions":"< Airflow 2.2.0 (provider version 2.0.1 and earlier)"},{"fix":"Verify that `pip install apache-airflow-providers-sendgrid` completed successfully in the environment where your Airflow workers run. Check your `requirements.txt` if using a managed Airflow service like MWAA or Astronomer, and ensure all dependencies are correctly installed. A common cause is misconfigured virtual environments or Docker images.","message":"Incorrect `ModuleNotFoundError` when DAGs try to import `airflow.providers.sendgrid.operators` or `hooks`. This usually indicates that the provider package was not installed correctly or there are Python environment issues in the Airflow worker context.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[{"fix":"Install the package using pip: 'pip install apache-airflow-providers-sendgrid'.","cause":"The 'apache-airflow-providers-sendgrid' package is not installed in the Airflow environment.","error":"ModuleNotFoundError: No module named 'airflow.providers.sendgrid'"},{"fix":"Update the import statement to: 'from airflow.providers.sendgrid.hooks.sendgrid import SendGridHook'.","cause":"The 'SendGridHook' class has been moved or renamed in the 'apache-airflow-providers-sendgrid' package.","error":"ImportError: cannot import name 'SendGridHook' from 'airflow.providers.sendgrid.hooks.sendgrid'"},{"fix":"Import 'SendGridHook' from its specific module: 'from airflow.providers.sendgrid.hooks.sendgrid import SendGridHook'.","cause":"The 'SendGridHook' class is not directly accessible from the 'airflow.providers.sendgrid' module.","error":"AttributeError: module 'airflow.providers.sendgrid' has no attribute 'SendGridHook'"},{"fix":"Update the import statement to: 'from airflow.providers.sendgrid.operators.sendgrid import SendGridOperator'.","cause":"The 'SendGridOperator' class has been moved or renamed in the 'apache-airflow-providers-sendgrid' package.","error":"ImportError: cannot import name 'SendGridOperator' from 'airflow.providers.sendgrid.operators.sendgrid'"},{"fix":"Install the 'sendgrid' package using pip: 'pip install sendgrid'.","cause":"The 'sendgrid' Python package, a dependency of 'apache-airflow-providers-sendgrid', is not installed.","error":"ModuleNotFoundError: No module named 'sendgrid'"}]}