Skip to content

MSSQL

Installation

pip install "toolfront[mssql]"

Connection URL

Connect to MSSQL by passing a connection URL to the Database constructor:

1
2
3
4
5
from toolfront import Database

db = Database(url="mssql://{user}:{password}@{host}:{port}")

revenue = db.ask("What's our total revenue this month?")

Connection Parameters

Alternatively, connect using the Database.from_mssql() method with parameters:

from toolfront import Database

db = Database.from_mssql(
    host="localhost",
    port=1433,
    database="sales",
    user="user",
    password="pass"
)

revenue = db.ask("What's our total revenue this month?")
PARAMETER DESCRIPTION
host

Address of MSSQL server to connect to. Default is 'localhost'.

TYPE: str DEFAULT: 'localhost'

user

Username. Leave blank to use Integrated Authentication.

TYPE: str DEFAULT: None

password

Password. Leave blank to use Integrated Authentication.

TYPE: str DEFAULT: None

port

Port of MSSQL server to connect to. Default is 1433.

TYPE: int DEFAULT: 1433

database

The MSSQL database to connect to.

TYPE: str DEFAULT: None

driver

ODBC Driver to use. On Mac and Linux this is usually 'FreeTDS'. On Windows, it is usually one of: - ODBC Driver 11 for SQL Server - ODBC Driver 13 for SQL Server (for both 13 and 13.1) - ODBC Driver 17 for SQL Server - ODBC Driver 18 for SQL Server See https://learn.microsoft.com/en-us/sql/connect/odbc/windows/system-requirements-installation-and-driver-files

TYPE: str DEFAULT: None

match_schema

Regex pattern to filter schemas. Mutually exclusive with match_tables.

TYPE: str DEFAULT: None

match_tables

Regex pattern to filter tables. Mutually exclusive with match_schema.

TYPE: str DEFAULT: None

**kwargs

Additional keyword arguments to pass to PyODBC.

TYPE: Any DEFAULT: {}