{"library":"mssql-python","title":"MSSQL Python Driver","description":"mssql-python is the official Microsoft Python library for interacting with Microsoft SQL Server, Azure SQL, and SQL databases in Fabric. It provides high-performance data access, bulk copy operations, and Apache Arrow integration. Currently at version 1.5.0, the library maintains an active release cadence with regular enhancements and bug fixes.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install mssql-python"],"cli":null},"imports":["import mssql_python\nconn = mssql_python.connect(...)"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport mssql_python\n\n# Ensure the ODBC Driver 18 for SQL Server is installed and configured.\n# On Debian/Ubuntu: curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -\n#                     curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list\n#                     sudo apt update\n#                     sudo ACCEPT_EULA=Y apt install msodbcsql18\n#                     sudo ACCEPT_EULA=Y apt install mssql-tools18\n# On macOS: brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release\n#            brew update\n#            ACCEPT_EULA=Y brew install msodbcsql18 mssql-tools18\n\n# Connection details from environment variables (recommended for production)\nSERVER = os.environ.get('MSSQL_SERVER', 'localhost')\nDATABASE = os.environ.get('MSSQL_DATABASE', 'master')\nUID = os.environ.get('MSSQL_USERNAME', '')\nPWD = os.environ.get('MSSQL_PASSWORD', '')\n\n# Construct the connection string. Make sure the DRIVER matches your installed ODBC driver.\n# For Windows, it might be 'ODBC Driver 17 for SQL Server' or 'SQL Server'.\nconnection_string = (\n    f\"DRIVER={{ODBC Driver 18 for SQL Server}}মনের;\"\n    f\"SERVER={SERVER};\"\n    f\"DATABASE={DATABASE};\"\n) # Omit UID/PWD if using Windows Authentication or EntraID\n\nif UID and PWD:\n    connection_string += f\"UID={UID};PWD={PWD};\"\n\ntry:\n    with mssql_python.connect(connection_string) as cnxn:\n        with cnxn.cursor() as cursor:\n            # Execute a simple query\n            cursor.execute(\"SELECT @@SERVERNAME, @@VERSION\")\n            row = cursor.fetchone()\n            if row:\n                print(f\"Connected to: {row[0]}\")\n                print(f\"SQL Server Version: {row[1]}\")\n\n            # Example: Insert data\n            cursor.execute(\"CREATE TABLE IF NOT EXISTS test_table (id INT PRIMARY KEY, name NVARCHAR(50))\")\n            cnxn.commit()\n            print(\"Table 'test_table' ensured.\")\n\n            cursor.execute(\"INSERT INTO test_table (id, name) VALUES (?, ?)\", 1, 'Hello')\n            cnxn.commit()\n            print(\"Inserted row (1, 'Hello').\")\n\n            # Example: Fetch all data\n            cursor.execute(\"SELECT id, name FROM test_table\")\n            for row in cursor.fetchall():\n                print(f\"Fetched: {row}\")\n\nexcept mssql_python.Error as ex:\n    sqlstate = ex.args[0]\n    print(f\"MSSQL Error: {sqlstate} - {ex}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to connect to a Microsoft SQL Server database using `mssql-python`, execute a simple query, create a table, insert data, and fetch results. It highlights the use of environment variables for secure credential management and the recommended `with` statement for connection and cursor management.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"1.7.0","pypi_latest":"1.7.0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":80,"avg_install_s":4.2,"avg_import_s":0.09,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"mssql-python","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"105.4M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"mssql-python","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.6,"import_time_s":0.05,"mem_mb":3.1,"disk_size":"107M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"mssql-python","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"110.5M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"mssql-python","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.2,"import_time_s":0.12,"mem_mb":3.4,"disk_size":"112M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"mssql-python","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"110.5M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"mssql-python","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.8,"import_time_s":0.09,"mem_mb":3.3,"disk_size":"111M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"mssql-python","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"114.5M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"mssql-python","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4,"import_time_s":0.11,"mem_mb":3.6,"disk_size":"115M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"mssql-python","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"mssql-python","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":1.7,"import_time_s":null,"mem_mb":null,"disk_size":null}]}}