cTDS

https://github.com/koddachad/k_ctds/actions/workflows/ci-cd.yml/badge.svg https://ci.appveyor.com/api/projects/status/tlgkdm69ldx7wc78?svg=true https://img.shields.io/pypi/v/k-ctds.svg https://codecov.io/github/koddachad/k_ctds/graph/badge.svg

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