A Python library for interacting with Microsoft SQL Server
Actively maintained. Last release 3 days ago, commits in 26 of the last 26 weeks. A safe choice.
pip install mssql-pythonGeneral Availability Release
mssql‑python is now Generally Available (GA) as Microsoft’s official Python driver for SQL Server, Azure SQL, and SQL databases in Fabric. This release delivers a production‑ready, high‑performance, and developer‑friendly experience.
What makes mssql-python different?
Powered by DDBC – Direct Database Connectivity
Most Python SQL Server drivers, including pyodbc, route calls through the Driver Manager, which has slightly different implementations across Windows, macOS, and Linux. This results in inconsistent behavior and capabilities across platforms. Additionally, the Driver Manager must be installed separately, creating friction for both new developers and when deploying applications to servers.
At the heart of the mssql-python driver is DDBC (Direct Database Connectivity) — a lightweight, high-performance C++ layer that replaces the platform’s Driver Manager.
Key Advantages:
- Provides a consistent, cross-platform backend that handles connections, statements, and memory directly.
- Interfaces directly with the native SQL Server drivers.
- Integrates with the same TDS core library that powers the ODBC driver.
Why is this architecture important?
By simplifying the architecture, DDBC delivers:
- Consistency across platforms
- Lower function call overhead
- Zero external dependencies on Windows (
pip install mssql-pythonis all you need) - Full control over connections, memory, and statement handling
Built with PyBind11 + Modern C++ for Performance and Safety
To expose the DDBC engine to Python, mssql-python uses PyBind11 – a modern C++ binding library.
PyBind11 provides:
- Native-speed execution with automatic type conversions
- Memory-safe bindings
- Clean and Pythonic API, while performance-critical logic remains in robust, maintainable C++.
What's new in v1.19.0
Enhancements
- Connection Retry Policy - Add optional
RetryPolicyconfiguration for retrying transient failures duringconnect()andConnection()initialization; existing behavior is unchanged without a policy (#751). - Table-Valued Parameters - Add
TableValuedParameterdefinitions and synchronous execution through the default ODBC provider, including streamed rows, empty inputs, and nullable cells (#789). - Structured Error Diagnostics - Expose optional and attributes on DB-API exceptions for synchronous ODBC errors while preserving existing exception messages and arguments (#909, #913).