August 12th, 2025
heart2 reactions

mssql-python vs pyodbc: Benchmarking SQL Server Performance

Saumya Garg
Software Engineer II

c1014e61 a66d 4807 ab58 655671044f49 image

Reviewed by Imran Masud and Sumit Sarabhai

When it comes to working with Microsoft SQL Server in Python, pyodbc has long been the de facto driver. It’s mature, trusted and has been serving the community well for years.

But as applications scale and Python becomes more central to modern data workflows — from microservices to data engineering and platforms like Microsoft Fabric — there’s a growing need to modernize and improve the developer experience. 

So, can we take this further?

Meet mssql-python – a modern SQL Server driver for Python that rethinks the architecture from the ground up while preserving a familiar experience for developers. It is purpose-built for:

  • Security
  • Performance
  • Memory safety
  • Cross-platform support

Try it here: pip install mssql-python

Calling all Python + SQL developers! We invite the community to try out mssql-python and help us shape the future of high-performance SQL Server connectivity in Python.!

To evaluate how it stacks up against pyodbc, we ran a comprehensive suite of performance benchmarks using the excellent Richbench tool. The results? Let’s just say they speak volumes.

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. 

With mssql-python, we made a bold decision. At the heart of the 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 ODBC driver (msodbcsql18).
  • Integrates with the same TDS core library that powers the ODBC driver.

Why This Architecture Matters?

By owning the layer that the ODBC driver depends on, DDBC delivers:

  • Provides consistency across platforms. 
  • Lower function call overhead
  • Zero external dependencies (pip install mssql-python is all you need) 
  • Full control over connections, memory and statement handling 

This architecture gives mssql-python its core advantages – speed, control and simplicity.

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, instead of ctypes. Why is that important?

With ctypes, every call between Python and the ODBC driver involved costly type conversions, manual pointer management, and is slow and unsafe.

PyBind11 solves all of this. It provides:

  • Native-speed execution with automatic type conversions
  • Memory-safe bindings
  • Driver API feel clean and Pythonic, while the performance-critical logic remains in robust, maintainable C++.

Benchmark Setup

  • Client Machine
    • Windows 11 Pro (64-bit)
    • Intel Core i7 (12th Gen), 32 GB RAM, NVMe SSD
    • Python 3.13.5(64-bit)
  • Database
    • Azure SQL Database
    • General Purpose (Serverless)
    • vCores: 1
    • Max storage: 32 GB
  • Driver Versions
    • mssql-python: v0.8.1
    • pyodbc: v5.2.0  
  • Tools
    • richbench – 5 runs × 5 samples per operation
  • Connection Pooling
    • Enabled in both drivers to simulate realistic app conditions
  • Benchmark script
    • Following is the snippet of the benchmark script used:

image 4 image

Benchmark Script

If you want to reproduce or extend our tests, checkout the complete script on GitHub.

Benchmark Summary

mssql-python outperforms pyodbc across most operations:

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

Across the board, the mssql-python driver demonstrated significantly faster execution times for common SQL operations, especially on:

  • Lightweight query handling
  • Fast connection reuse
  • Low-latency fetches and inserts

These results indicate highly efficient execution paths, minimal overhead, and strong connection reuse capabilities.

Disclaimer on Performance Benchmarks

The performance tests comparing mssql-python and pyodbc were conducted using a controlled set of queries designed to evaluate core driver capabilities. Real-world results may vary based on query patterns, data volumes, and system configurations.

We welcome feedback and real-world usage insights from the community. If you encounter performance issues or have suggestions, please raise issues on Github, we’re actively listening and committed to improving the experience.

Visual Snapshot

We captured this benchmark data in a clean tabular format using richbench tool. Here’s a quick glance at the relative performance:

undefined image

Analysis & Insights

  • Low-Latency Wins: SELECT, UPDATE, DELETE saw the largest improvements from 2× to 4× faster.
  • Complex Queries: Joins and Nested Queries showed ~4× improvements, due to lower per-call overhead and faster execution cycle.
  • Optimized Fetching: fetchone() and fetchmany() showed strong gains due to better buffer handling.
  • Connection Scaling: Creating 1000 concurrent connections was 16.5× faster, thanks to optimized pooling and connection caching in DDBC.
  • Bulk Insert Gains: Inserts ran 8.6× faster, aided by native buffer reuse and low-level batching.

What’s Next?

We’re actively improving the driver and here’s what’s in the pipeline:

  • Seamless Migration Support: We’re working on making the migration experience from pyodbc seamless, with familiar APIs and helpful migration guides.
  • Performance benchmarks for Linux and macOS environments.
  • Stress-testing under real-world application loads.
  • Bulk Copy (BCP) support for ultra-fast ingestion.
  • Community engagement for feedback and contributions.

Performance tuning is a key priority, and we’re committed to delivering consistent improvements in upcoming releases.

Join the Journey

If you’re building high-performance apps with SQL Server in Python, mssql-python is a fast, modern and compelling alternative to pyodbc. It is:

  • Faster across key operations
  • Safe and memory efficient
  • Architected for modern Python-C++ interoperability
  • Easy to install and integrate

Join the Early Customer Program

If you’re interested in becoming an early dogfooder and showcase your journey at Microsoft Ignite – we’d love to hear from you!

Apply here to join the Early Customer Program.

🚀Get early access, influence the roadmap, and work directly with the team!

Try It and Share Your Feedback! 

We invite you to: 

  1. Check-out the mssql-python driver and integrate it into your projects. 
  2. Share your thoughts: Open issues, suggest features, and contribute to the project. 
  3. Join the conversation: GitHub Discussions | SQL Server Tech Community. 

Use Python Driver with Free Azure SQL Database

You can use the Python Driver with the free version of Azure SQL Database!

✅ Deploy Azure SQL Database for free

✅ Deploy Azure SQL Managed Instance for free Perfect for testing, development, or learning scenarios without incurring costs.

Author

Saumya Garg
Software Engineer II

0 comments