Dead simple wrapper for pandas and sqlalchemy
Project description
sqlsorcery
Dead simple wrapper for pandas and sqlalchemy
Dependencies
- Python3.7
- Pipenv
- MS SQL odbc driver
Getting Started
- Install this library
$ pipenv install sqlsorcery
- Install MS SQL Drivers
wget https://packages.microsoft.com/debian/9/prod/pool/main/m/msodbcsql17/msodbcsql17_17.2.0.1-1_amd64.deb
apt-get update
apt-get install -y apt-utils unixodbc unixodbc-dev
yes | dpkg -i msodbcsql17_17.2.0.1-1_amd64.deb
- Setup a
.env
file with environment credentials
Single database environment:
DB_SERVER=
DB_PORT=
DB=
DB_USER=
DB_PWD=
For multi-database environment, use sql specific prefixes or specify connect vars at instantiation:
PG_SERVER=
PG_PORT=
PG_DB=
PG_USER=
PG_PWD=
MS_SERVER=
MS_DB=
MS_USER=
MS_PWD=
or
from sqlsorcery import MSSQL
sql = MSSQL(server="server_host", db="dba_name", user="username", pwd="password")
Examples
Query a table:
from sqlsorcery import MSSQL
sql = MSSQL()
df = sql.query("SELECT * FROM my_table")
print(df)
Query from a .sql
file:
from sqlsorcery import MSSQL
sql = MSSQL()
df = sql.query_from_file("filename.sql")
print(df)
Insert into a table:
from sqlsorcery import MSSQL
import pandas as pd
sample_data = [
{ "name": "Test 1", "value": 98 },
{ "name": "Test 2", "value": 100 },
]
df = pd.DataFrame(sample_data)
sql = MSSQL()
sql.insert_into("table_name", df)
Execute a stored procedure:
from sqlsorcery import MSSQL
sql = MSSQL()
sql.exec_sproc("sproc_name")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sqlsorcery-0.1.1.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for sqlsorcery-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af89dfc9b225060f1b7b1da71d1ff1aaa091399be34578c8e40a9e0e31d8c516 |
|
MD5 | 27a843151caa1310a1ae530725aff34b |
|
BLAKE2b-256 | 03a6f0009220c96108c64a08200bc5b46076305114b567c9e139941861c56d74 |