cTDS
k-cTDS is a full Python DB API-2.0-compliant SQL Server database library for Linux, Windows, and Mac OS X supporting Python 3.
k-cTDS is a maintained fork of cTDS, originally developed by Zillow.
The full documentation for k-cTDS can be found here.
Features
Supports Microsoft SQL Server 2008 and up.
Complete DB API-2.0 support.
Python 3.9-3.14 support.
Bulk insert (bcp) support.
Written entirely in C.
Pre-built wheels with bundled FreeTDS and OpenSSL for Linux, macOS, and Windows.
TLS/SSL support out of the box (OpenSSL 3.0).
Installation
Install from PyPI using pip. Pre-built wheels are available for Linux (x86_64, aarch64), macOS (x86_64, arm64), and Windows (AMD64):
pip install k-ctds
That’s it — the wheels bundle FreeTDS and OpenSSL so there is nothing else to install. TLS/SSL connections to SQL Server (including Azure SQL) work out of the box.
Note
Pre-built wheels bundle OpenSSL 3.0 (Apache 2.0 license) and
FreeTDS 1.5.x (LGPL-2.0, dynamically linked). See
THIRD_PARTY_NOTICES for details.
Using a Custom FreeTDS
If you need to link against your own build of FreeTDS (for example, to use a newer version or one compiled with different options), install from source:
pip install k-ctds --no-binary k-ctds
Point the build at your FreeTDS installation using environment variables:
export CTDS_INCLUDE_DIRS=/path/to/freetds/include
export CTDS_LIBRARY_DIRS=/path/to/freetds/lib
export CTDS_RUNTIME_LIBRARY_DIRS=/path/to/freetds/lib
pip install k-ctds --no-binary k-ctds
On Debian/Ubuntu you can use the system FreeTDS:
sudo apt-get install freetds-dev python3-dev
pip install k-ctds --no-binary k-ctds
On macOS with Homebrew:
brew install freetds
pip install k-ctds --no-binary k-ctds
On Windows (requires Visual Studio 2022 Build Tools, CMake, and 7-Zip):
# Build FreeTDS from source (uses the included helper script)
./windows/freetds-install.ps1
$Env:CTDS_INCLUDE_DIRS = "$(pwd)/build/include"
$Env:CTDS_LIBRARY_DIRS = "$(pwd)/build/lib"
pip install k-ctds --no-binary k-ctds
Dependencies
When installed from a pre-built wheel: none — FreeTDS, OpenSSL, and all native dependencies are bundled.
When installed from source: FreeTDS and its development headers must be available on the system.
Index
Table of Contents
- Getting Started
- Basic Example
- Executing SQL
- Calling Stored Procedures
- Reading Results
- Transactions
- Bulk Insert
- Connection Pooling
- TLS/SSL Encryption
- Frequently Asked Questions
- API Reference
- Change Log
- Unreleased
- v2.1.1
- v2.1.0
- v2.0.0
- 1.15.0 - 2026-02-11
- [1.14.0] - 2021-03-25
- [1.13.0] - 2020-11-12
- [1.12.0] - 2020-03-07
- [1.11.0] - 2019-11-14
- [1.10.1] - 2019-06-27
- [1.10.0] - 2019-04-15
- [1.9.0] - 2018-11-05
- [1.8.0] - 2018-09-07
- [1.7.0] - 2018-01-24
- [1.6.3] - 2017-12-05
- [1.6.2] - 2017-11-27
- [1.6.1] - 2017-11-20
- [1.6.0] - 2017-11-17
- [1.5.0] - 2017-10-16
- [1.4.1] - 2017-09-29
- [1.4.0] - 2017-09-13
- [1.3.2] - 2017-07-25
- [1.3.1] - 2017-05-31
- [1.3.0] - 2017-03-15
- [1.2.3] - 2017-03-13
- [1.2.2] - 2017-01-10
- [1.2.1] - 2016-12-27
- [1.2.0] - 2016-12-27
- [1.1.0] - 2016-11-14
- [1.0.8] - 2016-08-17
- [1.0.7] - 2016-08-15
- [1.0.6] - 2016-08-15
- [1.0.5] - 2016-05-23
- [1.0.4] - 2016-05-19
- [1.0.3] - 2016-03-31
- [1.0.2] - 2016-03-15
- [1.0.1] - 2016-03-14
- [1.0.0] - 2016-03-14