pyodbc is pretty much the industry-standard driver for people who want to work with Microsoft SQL Server in Python. This is primarily due to its active community, age, and overall stability. However, Microsoft has recently announced a preview of its own mssql-python driver, which it boasts is miles better than pyodbc.
In a detailed blog post, Microsoft has emphasized that mssql-python is built with performance, security, memory-safety, and cross-platform support in mind. It"s designed to take advantage of modern architectures, which is why it utilizes a platform-agnostic C++ layer called Direct Database Connectivity (DDBC). This is an alternative to Driver Manager which is leveraged by other drivers like pyodbc, and is also why developers sometimes get inconsistent behavior based on the platform they use it in.
DDBC provides a consistent cross-platform backend that interacts directly with the native SQL Server ODBC driver, offering a lower function call overhead, no external dependencies, and granular control over connections and memory handling.
When Microsoft benchmarked mssql-python versus pyodbc on an Azure SQL Database on a Windows 11 Pro machine with an Intel Core i7 processor and 32GB of RAM, it noticed significant performance improvements, which have been tabulated below:
| Category | mssql-python vs. pyodbc |
|---|---|
| Core SQL (SELECT, INSERT, UPDATE, DELETE) | 2× to 4× faster |
| Join, Nested, and Complex Queries | 3.6× to 4× faster |
| Fetch Operations (One & Many) | 3.6 to ~3.7× faster |
| Stored Procedures, Transactions | ~2.1× to ~2.6× faster |
| Batch Inserts | ~8.6x faster |
| 1000 Connections | 16.5x faster |
As can be seen from the results above, mssql-python is significantly faster than pyodbc while performing major operations. That said, it is important to note that this is based on Microsoft"s test case and your own mileage in real-world scenarios may vary.
mssql-python is currently in preview and is maintained by Microsoft on GitHub. It currently supports Windows, macOS, and some Linux distros like Debian, Ubuntu, and RHEL; support for Alpine and SUSE Linux is planned later. In terms of what"s next, Microsoft is making it easier for developers to migrate from pyodbc to mssql-python, stress-testing the driver, benchmarking on Linux and macOS, and working on Bulk Copy (BCP) support. In the meantime, you can try out Microsoft"s only first party SQL Python driver by running the following command:
pip install mssql-python