GoMSSQL Python
Project description
gomssql-python
The purpose of this module is to provide a Python interface to the Golang gomssql-db module.
It was made very easy with the help of the Golang gopy module.
It has come about because it seems impossible to get away from memory leaks when you're dealing with UnixODBC and FreeTDS.
Versions
This version (0.91) is the last version to support Python 2; all versions after this have been subject to a refactor and support Python 3 only.
Limitations
- Python command needs to be prefixed with GODEBUG=cgocheck=0 (or have that in the environment)
Prerequisites
- Go 1.13
- Python 2.7+
- pip
- virtualenvwrapper
- pkgconfig/pkg-config
Installation (for prod)
python setup.py install
Installation (from PyPI)
python -m pip install gomssql-python
Installation (for prod)
python setup.py install
Making a python wheel install file (for distribution)
python setup.py bdist_wheel
Setup (for dev)
Ensure pkg-config is installed
mkvirtualenvwrapper -p (/path/to/pypy) gomssql-python
pip install -r requirements-dev.txt
./build.sh
GODEBUG=cgocheck=0 py.test -v
What's worth knowing if I want to further the development?
- gopy doesn't like Go interfaces; so make sure you don't have any public (exported) interfaces
- this includes a struct with a public property that may eventually lead to an interface
Example Python usage
To create an MSSQL session in Python do the following:
from gomssql_python import Connection
ip = "127.0.0.1"
port = 5432
database = "test"
username = "test"
password = "test"
conn_str = """
server=%s;
port=%i;
database=%s;
user id=%s;
password=%s;
""" % (
ip, port, database,
username, password
).replace('\n', '').replace(' ', '')
connection = Connection(conn_str)
cursor = connection.cursor()
query = "SELECT NOW()"
cursor.execute(query)
records = cursor.fetchall()
print("Records:")
print(records)
cursor.close()
connection.close()
To develop / run the tests
MOUNT_WORKSPACE=1 ./test.sh bash
./build.sh
py.test
To test the sdist package
py.test
To do some manual testing
./manual_test.sh
This will spin up a Docker container that tries to connect to a specific database (internal to FTP Solutions); if the database is not there it'll simply fail (which is a good way to manually test for leaking memory).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.