A lightweight module that wraps and extends the PyMSSQL library.
Project description
pymssql-utils
A lightweight module that wraps and extends the pymssql library.
The aim of this module is to make it easier to use pymssql by:
- Reducing the amount of boilerplate code needed.
- Returning a helpful
DatabaseResult
class for each execution. - Represents each row of data as a
Row
class which is tuple-like, but can index via column names and supports the **mapping syntax. - Being fully type hinted.
- Parsing various SQL Types to native Python types that Python misses.
- Making it easier to serialise your data.
- Providing various utility functions for building dynamic SQL queries or logging query output.
- Fixing various edge case bugs that arise when using pymssql.
The trade-off with "baking in" various patterns (primarily opening a new connection on every execution) is that this module is opinionated as to what best practice is, and might not be suitable for all use cases. If this module doesn't make your life easier please raise critiques or suggestions via Github.
This module was created naturally over the course of a few years of using pymssql in various projects.
Installation
This module can be installed via pip: pip install pymssql-utils
.
This module requires Python >= 3.6
Quick Start (TODO)
Running a simple query:
import os
import pymssqlutils as sql
os.environ["DB_NAME"] = "MASTER"
Notes
Why pymssql when Microsoft officially recommends pyodbc (opinion)?
ODBC drivers add an extra layer between Python and SQL Server which can introduce issues that outway the benefits of pyodbc. The drivers have various levels of support on differeing linux distributions, and if you develop in containers or require to run the same code on various platforms you can run into issues. There are other minor reasons that I prefer pymssql, e.g. pymssql's parameter subsitution is done client-side leading to better visibiltiy on what the server is actually running. And pymssql (tries to) supports DATETIMEOFFSET SQL type while pyodbc does not.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pymssql_utils-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6015ec5f1a14d21de12a299739e9177ec6641f1d913b69ae0798af2779e44fee |
|
MD5 | 48919786bd928d1f1a17c9b189cfb69e |
|
BLAKE2b-256 | fd0473b4611968c4f7fc1d771b3740e2c35dbffebfcda35355277f1521e417dc |