Skip to content

Quantco/pytsql

Repository files navigation

pytsql

CI Documentation Status Conda-forge PypiVersion

pytsql allows to run mssql scripts, typically run from GUIs, from Python.

This, in turn, eases concurrent, scheduled and chained execution of scripts in a workflow. Put differently, it enables automated execution of Microsoft sql server scripts.

Moreover, pytsql supports parametrization of scripts, akin to templating.

Please have a look at our documentation if you're curious about more details.

Installation

To install, execute:

pip install pytsql

or in a conda environment

mamba install pytsql

Be aware that depending on your platform, you'will need specific drivers (Windows, Linux, macOS).

Usage

pytsql is tailored to run with MSSQL. Other sql dialects are not supported.

The main function of interest is execute. It requires a sqlalchemy Engine object as well as the path to the sql script of interest. A typical use case might look as follows:

import pytsql
from sqlalchemy import sa

db_connection_string = "connection_to_my_database"
engine = sa.get_engine(db_connection_string)

pytsql.execute("my_sql_script.sql", engine)

Please also have a look at our documentation sections on usage and development.

Credits

Grammar is based on antlr4/grammars-v4.