DB-API interface to Microsoft SQL Server for Python. (new Cython-based version)
pymssql - DB-API interface to Microsoft SQL Server
Detailed information on pymssql is available on the website:
New development is happening on GitHub at:
There is a Google Group for discussion at:
Do you use pymssql?
Can you take a minute and fill out this survey to help us prioritize development tasks?
Version 2.1.0 - 2014-02-25 - Marc Abramowitz
Sphinx-based documentation (GH-149)
Read it online at http://pymssql.org/
Thanks, Ramiro Morales!
“Green” support (GH-135)
Lets you use pymssql with cooperative multi-tasking systems like gevent and have pymssql call a callback when it is waiting for a response from the server. You can set this callback to yield to another greenlet, coroutine, etc. For example, for gevent, you could do:
def wait_callback(read_fileno): gevent.socket.wait_read(read_fileno) pymssql.set_wait_callback(wait_callback)
The above is useful if you’re say, running a gunicorn server with the gevent worker. With this callback in place, when you send a query to SQL server and are waiting for a response, you can yield to other greenlets and process other requests. This is super useful when you have high concurrency and/or slow database queries and lets you use less gunicorn worker processes and still handle high concurrency.
Better error messages.
E.g.: For a connection failure, instead of:
pymssql.OperationalError: (20009, 'Net-Lib error during Connection refused')
the dberrstr is also included, resulting in:
pymssql.OperationalError: (20009, 'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist\nNet-Lib error during Connection refused\n')
In the area of error messages, we also made this change:
- execute: Raise ColumnsWithoutNamesError when as_dict=True and missing column names (GH-160)
because the previous behavior was very confusing; instead of raising an exception, we would just return row dicts with those columns missing. This prompted at least one question on the mailing list (https://groups.google.com/forum/?fromgroups#!topic/pymssql/JoZpmNZFtxM), so we thought it was better to handle this explicitly by raising an exception, so the user would understand what went wrong.
You are most likely to notice a difference from these when you are fetching a large number of rows.
Reworked row fetching (GH-159)
There was a rather large amount of type conversion occuring when fetching a row from pymssql. The number of conversions required have been cut down significantly with these changes. Thanks Damien, Churchill!
Modify get_row() to use the CPython tuple API (GH-178)
This drops the previous method of building up a row tuple and switches to using the CPython API, which allows you to create a correctly sized tuple at the beginning and simply fill it in. This appears to offer around a 10% boost when fetching rows from a table where the data is already in memory. Thanks Damien, Churchill!
MSSQLConnection: Add with (context manager) support (GH-171)
This adds with statement support for MSSQLConnection in the _mssql module – e.g.:
with mssqlconn() as conn: conn.execute_query("SELECT @@version AS version")
We already have with statement support for the pymssql module.
Allow passing in binary data (GH-179)
Use the bytearray type added in Python 2.6 to signify that this is binary data and to quote it accordingly. Also modify the handling of str/bytes types checking the first 2 characters for b‘0x’ and insert that as binary data.
Add support for binding uuid.UUID instances to stored procedures input params (GH-143)
Thanks, Ramiro Morales!
The version number is now stored in one place, in pymssql_version.h This makes it easier to update the version number and not forget any places, like I did with pymssql 2.0.1
Improved support for using py.test as test runner (GH-183)
Improved PEP-8 and pylint compliance
GH-142 (“Change how *.pyx files are included in package”) - this should prevent pymssql.pyx and _mssql.pyx from getting copied into the root of your virtualenv. Thanks, @Arfrever!
GH-145 (“Prevent error string growing with repeated failed connection attempts.”)
GH-151 (“err_handler: Don’t clobber dberrstr with oserrstr”)
GH-152 (“_mssql.pyx: Zero init global last_msg_* vars”)
GH-177 (“binary columns sometimes are processed as varchar”) Better mechanism for pymssql to detect that user is passing binary data.
buffer overflow fix (GH-182)
Return uniqueidentifer columns as uuid.UUID objects on Python 3
Version 2.0.1 - 2013-10-27 - Marc Abramowitz
- MANIFEST.in: Add “*.rst” to prevent install error: “IOError: [Errno 2] No such file or directory: ‘ChangeLog_highlights.rst’”
Version 2.0.0 - 2013-10-25 - Marc Abramowitz
- First official release of pymssql 2.X (Cython-based code) to PyPI!
- Compared to pymssql 1.X, this version offers:
See ChangeLog for older history…
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.