Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/quantco/pytsql
Run mssql scripts from Python.
https://github.com/quantco/pytsql
database mssql sql tsql
Last synced: 2 months ago
JSON representation
Run mssql scripts from Python.
- Host: GitHub
- URL: https://github.com/quantco/pytsql
- Owner: Quantco
- License: bsd-3-clause
- Created: 2022-01-26T14:48:18.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T22:03:42.000Z (2 months ago)
- Last Synced: 2024-10-25T16:21:24.869Z (2 months ago)
- Topics: database, mssql, sql, tsql
- Language: C++
- Homepage:
- Size: 6.36 MB
- Stars: 14
- Watchers: 6
- Forks: 3
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pytsql
[![CI](https://github.com/Quantco/pytsql/workflows/CI/badge.svg)](https://github.com/Quantco/pytsql/actions)
[![Documentation Status](https://readthedocs.org/projects/pytsql/badge/?version=latest)](https://pytsql.readthedocs.io/en/latest/?badge=latest)
[![Conda-forge](https://img.shields.io/conda/vn/conda-forge/pytsql?logoColor=white&logo=conda-forge)](https://anaconda.org/conda-forge/pytsql)
[![PypiVersion](https://img.shields.io/pypi/v/pytsql.svg?logo=pypi&logoColor=white)](https://pypi.org/project/pytsql)`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](https://pytsql.readthedocs.io/en/latest/?badge=latest) if you're curious about more details.
## Installation
To install, execute:
```bash
pip install pytsql
```or in a `conda` environment
```bash
mamba install pytsql
```Be aware that depending on your platform, you'will need specific drivers ([Windows](https://docs.microsoft.com/en-us/sql/connect/odbc/windows/microsoft-odbc-driver-for-sql-server-on-windows?view=sql-server-ver15), [Linux](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15), [macOS](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver15)).
## 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`][engine]
object as well as the path to the sql script of interest. A typical use case might look as follows:```python
import pytsql
from sqlalchemy import sadb_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](https://pytsql.readthedocs.io/en/latest/usage.html#parametrization) and
[development](https://pytsql.readthedocs.io/en/latest/development.html).[engine]: https://docs.sqlalchemy.org/en/14/core/engines.html
## Credits
Grammar is based on [antlr4/grammars-v4](https://github.com/antlr/grammars-v4/tree/master/sql/tsql).