microsoft/mssql-python
Python
Captured source
source ↗microsoft/mssql-python
Description: Microsoft Python Driver for SQL Server
Language: Python
License: NOASSERTION
Stars: 433
Forks: 50
Open issues: 67
Created: 2025-01-24T12:21:04Z
Pushed: 2026-06-11T03:06:57Z
Default branch: main
Fork: no
Archived: no
README:
Microsoft Python Driver for SQL Server
mssql-python is a Python driver for Microsoft SQL Server and the Azure SQL family of databases. It leverages Direct Database Connectivity (DDBC) that enables direct connections to SQL Server without requiring an external driver manager. Designed to comply with the DB API 2.0 specification, this driver also introduces Pythonic enhancements for improved usability and functionality. It supports a full range of database operations, including connection management, query execution, and transaction handling.
The driver is compatible with all the Python versions >= 3.10
Documentation | Release Notes | Roadmap
> Note: > This project is now Generally Available (GA) and ready for production use. We’ve completed core functionality and incorporated feedback from the preview phase. >
Installation
Windows: mssql-python can be installed with pip
pip install mssql-python
MacOS: mssql-python can be installed with pip
# For Mac, OpenSSL is a pre-requisite - skip if already present brew install openssl pip install mssql-python
Linux: mssql-python can be installed with pip
# For Alpine apk add libtool krb5-libs krb5-dev # For Debian/Ubuntu apt-get install -y libltdl7 libkrb5-3 libgssapi-krb5-2 # For RHEL dnf install -y libtool-ltdl krb5-libs # For SUSE zypper install -y libltdl7 libkrb5-3 libgssapi-krb5-2 # For SUSE/openSUSE zypper install -y libltdl7 # For Azure Linux tdnf distro-sync && tdnf install -y libtool-ltdl krb5-libs glibc-iconv pip install mssql-python
Key Features
Supported Platforms
Windows, MacOS and Linux (manylinux - Debian, Ubuntu, RHEL, SUSE (x64 only) & musllinux - Alpine)
> Note: > SUSE Linux ARM64 is not supported. Please use x64 architecture for SUSE deployments.
Support for Microsoft Entra ID Authentication
The Microsoft mssql-python driver enables Python applications to connect to Microsoft SQL Server, Azure SQL Database, or Azure SQL Managed Instance using Microsoft Entra ID identities. It supports a variety of authentication methods, including username and password, Microsoft Entra managed identity (system-assigned and user-assigned), Integrated Windows Authentication in a federated, domain-joined environment, interactive authentication via browser, device code flow for environments without browser access, and the default authentication method based on environment and configuration. This flexibility allows developers to choose the most suitable authentication approach for their deployment scenario.
EntraID authentication is now fully supported on MacOS and Linux but with certain limitations as mentioned in the table:
| Authentication Method | Windows Support | macOS/Linux Support | Notes | |----------------------|----------------|---------------------|-------| | ActiveDirectoryPassword | ✅ Yes | ✅ Yes | Username/password-based authentication | | ActiveDirectoryInteractive | ✅ Yes | ✅ Yes | Interactive login via browser; requires user interaction | | ActiveDirectoryMSI (Managed Identity) | ✅ Yes | ✅ Yes | For Azure VMs/containers with managed identity | | ActiveDirectoryServicePrincipal | ✅ Yes | ✅ Yes | Use client ID and secret or certificate | | ActiveDirectoryIntegrated | ✅ Yes | ✅ Yes | Now supported on Windows, macOS, and Linux (requires Kerberos/SSPI or equivalent configuration) | | ActiveDirectoryDeviceCode | ✅ Yes | ✅ Yes | Device code flow for authentication; suitable for environments without browser access | | ActiveDirectoryDefault | ✅ Yes | ✅ Yes | Uses default authentication method based on environment and configuration |
> For more information on Entra ID please refer this document
Connection Pooling
The Microsoft mssql_python driver provides built-in support for connection pooling, which helps improve performance and scalability by reusing active database connections instead of creating a new connection for every request. This feature is enabled by default. For more information, refer Connection Pooling Wiki.
DBAPI v2.0 Compliance
The Microsoft mssql-python module is designed to be fully compliant with the DB API 2.0 specification. This ensures that the driver adheres to a standardized interface for database access in Python, providing consistency and reliability across different database systems. Key aspects of DBAPI v2.0 compliance include:
- Connection Objects: Establishing and managing connections to the database.
- Cursor Objects: Executing SQL commands and retrieving results.
- Transaction Management: Supporting commit and rollback operations to ensure data integrity.
- Error Handling: Providing a consistent set of exceptions for handling database errors.
- Parameter Substitution: Allowing the use of placeholders in SQL queries to prevent SQL injection attacks.
By adhering to the DB API 2.0 specification, the mssql-python module ensures compatibility with a wide range of Python applications and frameworks, making it a versatile choice for developers working with Microsoft SQL Server, Azure SQL Database, and Azure SQL Managed Instance.
Enhanced Pythonic Features
The driver offers a suite of Pythonic enhancements that streamline database interactions, making it easier for developers to execute queries, manage connections, and handle data more efficiently.
Getting Started Examples
Connect to SQL Server and execute a simple query:
import mssql_python # Establish a connection # Specify connection string (semicolon-delimited key=value format preserved) # Uses Azure Entra ID Interactive authentication — no password in the string. connection_string =…
Excerpt shown — open the source for the full document.
Notability
notability 4.0/10New driver repo from Microsoft, moderate stars