Registry / database / apache-airflow-providers-microsoft-mssql

apache-airflow-providers-microsoft-mssql

JSON →
library4.5.1pypypi✓ verified 52d ago

The Apache Airflow Microsoft MSSQL Provider enables seamless interaction with Microsoft SQL Server databases within Airflow DAGs. It provides hooks and operators for connecting to, querying, and managing data in MSSQL. This provider is part of the larger Apache Airflow ecosystem, currently at version 4.5.1, and receives updates aligned with Airflow's release cycle, as well as independent bug fixes and feature enhancements.

databaseworkflowazure
pip install apache-airflow-providers-microsoft-mssql
Install & Compatibility
Where this runs
tested against v4.6.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 5.334s · 259.2MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 23.0s · import 4.834s · 256MB
259MB installed
● package 259MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MsSqlHook
from airflow.providers.microsoft.mssql.hooks.mssql import MsSqlHook
MsSqlOperator
from airflow.providers.microsoft.mssql.operators.mssql import MsSqlOperator
MsSqlToS3Operator
from airflow.providers.microsoft.mssql.transfers.mssql_to_s3 import MsSqlToS3Operator

This quickstart demonstrates a simple Airflow DAG that uses the `MsSqlOperator` to connect to a Microsoft SQL Server database and execute a basic SQL query. Before running, ensure you have an Airflow connection named `mssql_default` configured with the appropriate host, credentials, and optional driver settings in your Airflow UI or via CLI.

from __future__ import annotations import pendulum from airflow.models.dag import DAG from airflow.providers.microsoft.mssql.operators.mssql import MsSqlOperator # Configure an Airflow Connection named 'mssql_default' # Host: your_mssql_host # Port: 1433 (default) # Schema: your_database_name # Login: your_username # Password: your_password # Extra: {"driver": "ODBC Driver 17 for SQL Server"} (if using pyodbc) with DAG( dag_id="mssql_quickstart_dag", start_date=pendulum.datetime(2023, 1, 1, tz="UTC"), schedule=None, catchup=False, tags=["mssql", "example"], ) as dag: run_simple_query = MsSqlOperator( task_id="run_select_statement", mssql_conn_id="mssql_default", sql="SELECT 1 as result;", autocommit=True, )
airflow --version
Debug
Known issues
breakingThe `apache-airflow-providers-microsoft-mssql` provider now requires Python 3.10 or higher. Users running Airflow on older Python versions (e.g., 3.8, 3.9) must upgrade their Python environment to use provider version 4.0.0 and above.
fix
Upgrade your Python environment to 3.10 or newer. If unable to upgrade Python, pin the provider version to `<4.0.0` (e.g., `apache-airflow-providers-microsoft-mssql<4.0.0`).
affects: >=4.0.0
gotchaThis provider itself does not include the actual database drivers (`pymssql` or `pyodbc`). You must install one of these Python packages separately and ensure any necessary system-level ODBC drivers (for `pyodbc`) are also installed on your Airflow worker host.
fix
Choose your preferred driver: `pip install pymssql` OR `pip install pyodbc`. If using `pyodbc`, ensure the appropriate ODBC driver (e.g., 'ODBC Driver 17 for SQL Server') is installed and configured on the Airflow worker's operating system. Configure your Airflow connection's 'Extra' field to specify the driver, e.g., `{"driver": "ODBC Driver 17 for SQL Server"}`.
affects: All
gotchaConnection string issues are common. Especially with `pyodbc`, specific driver names and connection parameters (e.g., trust server certificate) often need to be passed in the 'Extra' field of the Airflow connection to ensure successful negotiation with the SQL Server.
fix
Carefully review MSSQL connection documentation for your specific SQL Server version and driver. Experiment with 'Extra' parameters like `{"driver": "{ODBC Driver 17 for SQL Server}", "autocommit": true, "Encrypt": "yes", "TrustServerCertificate": "yes"}`. Test the connection outside of Airflow using a simple Python script with your chosen driver to isolate connection issues.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'airflow.providers.microsoft.mssql'
The 'apache-airflow-providers-microsoft-mssql' package is not installed.
fix
pip install apache-airflow-providers-microsoft-mssql
ImportError: cannot import name 'MsSqlHook' from 'airflow.providers.microsoft.mssql.hooks.mssql'
The 'apache-airflow-providers-microsoft-mssql' package is not installed.
fix
pip install apache-airflow-providers-microsoft-mssql
ImportError: cannot import name 'MsSqlOperator' from 'airflow.providers.microsoft.mssql.operators.mssql'
The 'apache-airflow-providers-microsoft-mssql' package is not installed.
fix
pip install apache-airflow-providers-microsoft-mssql
Adaptive Server connection failed
This general connection error often indicates a problem with the connection details provided in the Airflow UI, network connectivity to the MSSQL server, or issues with the underlying `pymssql` library's ability to establish a connection. Common culprits include incorrect host, port, username, password, or firewall settings.
fix
Double-check all connection parameters (Host, Port, Login, Password, Schema) in the Airflow UI. Ensure the MSSQL server is accessible from where Airflow is running and that firewall rules permit the connection. Also, verify that the `pymssql` library (which `MsSqlHook` uses by default) is correctly installed and compatible with your MSSQL server version.
pyodbc.Error: ('01000', "[01000] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)")
This error signifies that the necessary ODBC driver for SQL Server is not installed or properly configured on the system where Airflow is running. The `pyodbc` library, often used for MSSQL connections, relies on a system-level ODBC driver to connect to the database.
fix
Install the appropriate Microsoft ODBC Driver for SQL Server on your system. For Linux environments, this typically involves adding Microsoft's package repositories and installing `msodbcsql17` (or newer) and `unixodbc-dev`. Ensure the driver is correctly referenced in your connection string if using `OdbcHook` or custom `pyodbc` connections.
Upgrade
Version history
4.6.1latest on PyPI
Audit
Dependencies
apache-airflow>=2.2.0requiredCore Airflow library required for running DAGs and tasks.
pymssqloptionalAn alternative database driver for MSSQL connections, often used for Linux environments. Required if you use 'pymssql' as a connection driver.
pyodbcoptionalODBC driver for MSSQL connections, common for Windows environments or when specific ODBC features are needed. Requires system-level ODBC drivers to be installed. Required if you use 'pyodbc' as a connection driver.
Agent activity
95 hits · last 30 days
node
14
claudebot
4
ahrefsbot
3
amazonbot
2
Amazon
1
bytedance
1
seranking-bot
1
Resources