Skip to content

About

SQLAlchemy dialect for mssql using pyodbc

Resources

Stars

18 stars

Watchers

1 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sqlalchemy_pyodbc_mssql

nox codecov

SQLAlchemy's SQL Server pyodbc dialect with focused workarounds for two SQL Server/ODBC limitations:

  • Repeated positional parameters in a SELECT expression and its GROUP BY expression are treated as different values by SQL Server.
  • SQL Server limits a statement to 2,100 parameters.

The dialect leaves ordinary statements parameterized. It uses SQLAlchemy's type-aware post-compile literal rendering for grouped expressions and expanding parameters. A conservative fallback handles statements containing more than 2,099 individual parameters.

Usage

Install the package and use mssql+pyodbc_mssql in place of mssql+pyodbc:

pip install sqlalchemy_pyodbc_mssql
mssql+pyodbc_mssql://user:password@server/database?driver=ODBC+Driver+18+for+SQL+Server

See SQLAlchemy's Microsoft SQL Server documentation for pyodbc connection options.

Dev

Copier Template

Project structure and tooling mostly derives from Coppy. See its documentation for context and additional instructions.

This project can be updated from the upstream repo, see Updating a Project.

Project Setup

From zero to hero (passing tests that is):

  1. Ensure host dependencies are installed

  2. Start docker service dependencies (if applicable):

    docker compose up -d

  3. Sync project virtualenv w/ lock file:

    uv sync

  4. Configure prek:

    prek install

  5. Run tests:

    nox

The fast tests run without SQL Server. Live contract tests run when MSSQL_TEST_URL is set. For ODBC Driver 18 and the supplied Compose service:

export MSSQL_TEST_URL='mssql+pyodbc_mssql://sa:SqlServer12!@127.0.0.1:1433/tempdb?driver=ODBC+Driver+18+for+SQL+Server&Encrypt=yes&TrustServerCertificate=yes'
nox -s pytest

CI uses Microsoft's official SQL Server 2022 image and probes readiness with sqlcmd before starting the Python 3.12, 3.13, and 3.14 test sessions.

Versions

Versions are date based. A version task shows and bumps versions:

  # Show current version
  mise run version show

  # Bump version based on date, tag, and push:
  mise run version bump

  # See other options
  mise run version -- --help

About

SQLAlchemy dialect for mssql using pyodbc

Resources

Stars

18 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages