DB-API interface to Microsoft SQL Server for Python. (new Cython-based version)
Project description
pymssql - DB-API interface to Microsoft SQL Server
A simple database interface for Python that builds on top of FreeTDS to provide a Python DB-API (PEP-249) interface to Microsoft SQL Server.
Detailed information on pymssql is available on the website:
New development is happening on GitHub at:
https://github.com/pymssql/pymssql
There is a Google Group for discussion at:
https://groups.google.com/forum/?fromgroups#!forum/pymssql
Do you use pymssql?
Can you take a minute and fill out this survey to help us prioritize development tasks?
https://www.surveymonkey.com/s/KMQ8BM5
Recent Changes
Version 2.1.4 - 2018-08-28
General
Drop support for versions of FreeTDS older than 0.91.
Add Python 3.7 support
Drop Python 3.3 support
Features
Support for new in SQL Server 2008 DATE, TIME and DATETIME2 data types (GH-156). The following conditions need to be additionally met so values of these column types can be returned from the database as their native corresponding Python data types instead of as strings:
Underlying FreeTDS must be 0.95 or newer.
TDS protocol version in use must be 7.3 or newer.
Thanks Ed Avis for the implementation. (GH-331)
Bug fixes
Fix tds_version _mssql connection property value for TDS version. 7.1 is actually 7.1 and not 8.0.
Version 2.1.3 - 2016-06-22 - Ramiro Morales
We now publish Linux PEP 513 manylinux wheels on PyPI.
Windows official binaries: Rollback changes to Windows binaries we had implemented in pymssql 2.1.2; go back to using:
A statically linked version of FreeTDS (v0.95.95)
No SSL support
Version 2.1.2 - 2016-02-10 - Ramiro Morales
Features
Add ability to set TDS protocol version from pymssql when connecting to SQL Server. For the remaining pymssql 2.1.x releases its default value will be 7.1 (GH-323)
Add Dockerfile and a Docker image and instructions on how to use it (GH-258). This could be a convenient way to use pymssql without having to build stuff. See http://pymssql.readthedocs.org/en/latest/intro.html#docker Thanks Marc Abramowitz.
Floating point values are now accepted as Stored Procedure arguments (GH-287). Thanks Runzhou Li (Leo) for the report and Bill Adams for the implementation.
Send pymssql version in the appname TDS protocol login record field when the application doesn’t provide one (GH-354)
Bug fixes
Fix a couple of very common causes of segmentation faults in presence of network a partition between a pymssql-based app and SQL Server (GH-147, GH-271) Thanks Marc Abramowitz. See also GH-373.
Fix failures and inconsistencies in query parameter interpolation when UTF-8-encoded literals are present (GH-185). Thanks Bill Adams. Also, GH-291.
Fix login_timeout parameter of pymssql.connect() (GH-318)
Fixed some cases of cursor.rowcont having a -1 value after iterating over the value returned by pymssql cursor fetchmany() and fetchone() methods (GH-141)
Remove automatic treatment of string literals passed in queries that start with '0x' as hexadecimal values (GH-286)
Fix build fatal error when using Cython >= 0.22 (GH-311)
Internals
Add Appveyor hosted CI setup for running tests on Windows (GH-347)
Travis CI: Use newer, faster, container-based infrastructure. Also, test against more than one FreeTDS version.
Make it possible to build official release files (sdist, wheels) on Travis & AppVeyor.
Version 2.1.1 - 2014-11-25 - Ramiro Morales
Features
Custom message handlers (GH-139)
The DB-Library API includes a callback mechanism so applications can provide functions known as message handlers that get passed informative messages sent by the server which then can be logged, shown to the user, etc.
_mssql now allows you to install your own message handlers written in Python. See the _msssql examples and reference sections of the documentation for more details.
Thanks Marc Abramowitz.
Compatibility with Azure
It is now possible to transparently connect to SQL Server instances accessible as part of the Azure cloud services.
Customizable per-connection initialization SQL clauses (both in pymssql and _mssql) (GH-97)
It is now possible to customize the SQL statements sent right after the connection is established (e.g. 'SET ANSI_NULLS ON;'). Previously it was a hard-coded list of queries. See the _mssql.MSSQLConnection documentation for more details.
Thanks Marc Abramowitz.
Added ability to handle instances of uuid.UUID passed as parameters for SQL queries both in pymssql and _mssql. (GH-209)
Thanks Marat Mavlyutov.
Allow using SQL Server autocommit mode from pymssql at connection opening time. This allows e.g. DDL statements like DROP DATABASE to be executed. (GH-210)
Thanks Marat Mavlyutov.
Documentation: Explicitly mention minimum versions supported of Python (2.6) and SQL Server (2005).
Incremental enhancements to the documentation.
Bug fixes
Handle errors when calling Stored Procedures via the .callproc() pymssql cursor method. Now it will raise a DB-API DatabaseException; previously it allowed a _mssql.MSSQLDatabaseException exception to surface.
Fixes in tds_version _mssql connections property value
Made it work with TDS protocol version 7.2. (GH-211)
The value returned for TDS version 7.1 is still 8.0 for backward compatibility (this is because such feature got added in times when Microsoft documentation labeled the two protocol versions that followed 7.0 as 8.0 and 9.0; later it changed them to 7.1 and 7.2 respectively) and will be corrected in a future release (2.2).
PEP 249 compliance (GH-251)
Added type constructors to increase compatibility with other libraries.
Thanks Aymeric Augustin.
pymssql: Made handling of integer SP params more robust (GH-237)
Check lower bound value when convering integer values from to Python to SQL (GH-238)
Internals
Completed migration of the test suite from nose to py.test.
Added a few more test cases to our suite.
Tests: Modified a couple of test cases so the full suite can be run against SQL Server 2005.
Added testing of successful build of documentation to Travis CI script.
Build process: Cleanup intermediate and ad-hoc anciliary files (GH-231, GH-273)
setup.py: Fixed handling of release tarballs contents so no extraneous files are shipped and the documentation tree is actually included. Also, removed unused code.
Version 2.1.0 - 2014-02-25 - Marc Abramowitz
Features
Sphinx-based documentation (GH-149)
Read it online at http://pymssql.org/
Thanks, Ramiro Morales!
See:
“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 existnNet-Lib error during Connection refusedn’)
See: * https://github.com/pymssql/pymssql/pull/151
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.
See: * https://github.com/pymssql/pymssql/pull/160 * https://github.com/pymssql/pymssql/pull/168
Performance improvements
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!
See: * https://github.com/pymssql/pymssql/pull/158 * https://github.com/pymssql/pymssql/pull/159
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. See:
Allow passing in binary data (GH-179)
Use the bytesarray 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. See:
Add support for binding uuid.UUID instances to stored procedures input params (GH-143) Thanks, Ramiro Morales!
See: * https://github.com/pymssql/pymssql/pull/143 * https://github.com/pymssql/pymssql/commit/1689c83878304f735eb38b1c63c31e210b028ea7
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
Bug Fixes
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.”)
See:
GH-151 (“err_handler: Don’t clobber dberrstr with oserrstr”)
GH-152 (“_mssql.pyx: Zero init global last_msg_* vars”) See: https://github.com/pymssql/pymssql/pull/152
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
See ChangeLog for older history…
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 Distributions
Hashes for pymssql-2.1.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fd384371ddc260c12d79dc8bcc239c722d571d1701cba1ec7788617db603a06 |
|
MD5 | 8aad4edf7a2bcaedeb1ad1f16734741e |
|
BLAKE2b-256 | 450c81bf31194f4dc0ee06b429efe98ce2fc202876cd4749f95bddfb9f3b0a50 |
Hashes for pymssql-2.1.4-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c830088a8c1571e4606edd461d5f2291c8dacea2cd615466fb4764773d968949 |
|
MD5 | 32443c9d9564ed0f1c204999ff5a3b05 |
|
BLAKE2b-256 | e39e75b78d890a07e74f6876e1b22456f236887a4189d3e793cc04204ca15a32 |
Hashes for pymssql-2.1.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe7e4bf3c79b3f0425588bd99188e431727f4d6b19249dcb81b94e10d261d86f |
|
MD5 | 5efae42c6781d69f5ec3f3385768b019 |
|
BLAKE2b-256 | be09455835d22f84636dc646f4dc6afcc79c226d8bc253ef767ca8a922eec74a |
Hashes for pymssql-2.1.4-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a3869e6f0ea3a49f4faf8489638341578b4e638e86dc4067a69e8fa5d0469a2 |
|
MD5 | 1e6d5caec91f64370a55535fe55751cc |
|
BLAKE2b-256 | 7add95d34a5cf832c2185882185017576c6df40e4fc67083df26afaa5c9eb7e7 |
Hashes for pymssql-2.1.4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46dcd9c2f371d7d5744c22d6a3dc426b10debd12e0cab5b69c92f29b8eb90e21 |
|
MD5 | 01668a7b8543a0d0c2b2afb2891c4846 |
|
BLAKE2b-256 | bd3729e06859fc71620d8eb4841a7701c9f60859223e442686de28d7697bcd2e |
Hashes for pymssql-2.1.4-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 056dacf9120ae3a01955c52ce425b7ee7da499b27bd80f3bfcfb4013ae7adff8 |
|
MD5 | 224e7dee17e7c3304337c1336da028eb |
|
BLAKE2b-256 | ab10377aff1ba8c10a93ed75c48bcf4089c152c5c6f6a4a940b00051818910c4 |
Hashes for pymssql-2.1.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d30001a9e00dbbb7ca04922eeb4df89e946bb083bbf7114667b8cbb7e08d9a0c |
|
MD5 | 57f3507d6d5a5e6531529405a2d63a36 |
|
BLAKE2b-256 | 8480de3af1d2d76792841a94196c6c06c67fb4c3b11ae3a5f5811c5069b94d76 |
Hashes for pymssql-2.1.4-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47a567ed94618a89c83b8ce24c886ff65f0c063ef02ed7240b98ab953ca95b5d |
|
MD5 | d0c990614e3098889aae4314e019561a |
|
BLAKE2b-256 | 7de7760023e62f14ed6a88227d62142f35318060e7107368892823b0b0415b4a |
Hashes for pymssql-2.1.4-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc2f3f93711cb6262cee83f63e9e38021a79f0d1b4c0deec7f68de97b49a8938 |
|
MD5 | 61f6af06a254ee9f3e1d7778811e6691 |
|
BLAKE2b-256 | ccb180d6aca20d1809dd2d7b5f03c2d2a58f211d71e28d4713dce2fb9e7f3a64 |
Hashes for pymssql-2.1.4-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 254e3552b6a52b40cb437f4b75683e003398f8ce12da0e40908a07703882802d |
|
MD5 | 88be85c1e8a9f743c2842316cad637d0 |
|
BLAKE2b-256 | 5cfe906dda137a832d6857af277f5b75dd3d32c184c487390ab638eec9159f72 |
Hashes for pymssql-2.1.4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb340fbf5525ea51c5d4b704340a6fe8ec97e5380b5cd17107ea48179d1c1605 |
|
MD5 | c3507ae7960cffa860148492b6a7ffe9 |
|
BLAKE2b-256 | 81471fa6ef755f1149c290b07ad472c98a71601e35efd4f0817160f6fc65d8c7 |
Hashes for pymssql-2.1.4-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e730e1fbbde44227ad34c024e71c1764503cf97c3812c520766867d1ee916e68 |
|
MD5 | d01ef42a26f2bad7598d8a3ec96b83db |
|
BLAKE2b-256 | 73588e66c210642ff4dfdd89b70471704887d4579c9142e8bc46450219f5997c |
Hashes for pymssql-2.1.4-cp34-cp34m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c32df8c15dda0a23551348a51b7b41f0bfe25be8925c7afebcef977f89cceb62 |
|
MD5 | cf4cc27e72539fbb5833d6004132d7ca |
|
BLAKE2b-256 | 866134986f3350e1496de305917d34b9f1482792537960ee23bb751f5949d183 |
Hashes for pymssql-2.1.4-cp34-cp34m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e077af5c80e768976b47789644bd7ea211131b5d8ed174e44995b3ef34009aad |
|
MD5 | 59f7c542a53617a76f4be4d352a87b0f |
|
BLAKE2b-256 | d5dd391b51c0352e168e3783dce93d873b92cdb837e539cd91910a1203920960 |
Hashes for pymssql-2.1.4-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebecdd63e9a6c871dcd25c877895f9ed2ba96549743cb4d45d201fc478f1bf28 |
|
MD5 | f6863070bc45c796ecf6c5fa79ce2209 |
|
BLAKE2b-256 | 2508a5a8f76457fedc963cbcafb8c7033070ca6b84483aed56b7486dabbdcc5d |
Hashes for pymssql-2.1.4-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 084deb1462fb52c0d802b006c673f3a02ce562b7b3a2f65f6a6bd2162a0850a2 |
|
MD5 | 432f046903d6177590fefc73a24b3375 |
|
BLAKE2b-256 | 50ba922667bcd5327c1fb1f009424eeaf6caf669ad20d3d70a109568d0b0f667 |
Hashes for pymssql-2.1.4-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f58810f6917916af539948b3ed53881aca4aa7db80b662dcabcbf93a3cdea938 |
|
MD5 | 8c0131905d1f96998cd85584a1184e2d |
|
BLAKE2b-256 | a643c8430ec972c15999921cbc1bb8396049878695b78c182056bd03240d8c5d |
Hashes for pymssql-2.1.4-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3bf234eeb24ba6048ab1bb069395e3acd212376e91d8d7fdfdcfef60178cef4 |
|
MD5 | 665bbdeeb25418a56e0b444fbdcd2309 |
|
BLAKE2b-256 | e7ba64acfbd968083d6e8c5276b0cedd9a4226ac722a85c4bb63f7036c4a23ad |
Hashes for pymssql-2.1.4-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7544b8b1b38d101f0b7bd794d2da53dd19fee38e3dfe7312cd9bc87252347260 |
|
MD5 | e388bef26401ba5335f59c494a3f5c48 |
|
BLAKE2b-256 | a5d9ebcdebcc48557eb4d22bd0f0c3c82696e1feb0ded2667f08ea9170e6e898 |
Hashes for pymssql-2.1.4-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6da06dd6a37b3472b034a82fd156c63c6cb288b996a6ef252e874e343b37a254 |
|
MD5 | b11cf9088841e29a85ab07e085f9801f |
|
BLAKE2b-256 | 9328b2cd07f23d93dba38e09b05c71b348a3dbbea80e8b46231485ff10c61097 |
Hashes for pymssql-2.1.4-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfbce903ed29d2979168ac5d253e8241cb73901ec79c1e6692eb912ebc990be9 |
|
MD5 | aaf265c8b788cf9585d3dc0cb3019403 |
|
BLAKE2b-256 | 5978ee8176773c3c717a64977bea61c0a9c453e4ffd6f03e76a70d88e510b2ff |
Hashes for pymssql-2.1.4-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0479294789d7f230016d87e115a23e51617909611de7b1ced1263c1e365f6c91 |
|
MD5 | ea647f5985327da545d4119363e07114 |
|
BLAKE2b-256 | d715e7220eaa97e78611b9c3d4d33ad31a76a230c2b2287943222a04872bc756 |