Skip to main content

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

  1. Install this library
$ pipenv install sqlsorcery
  1. 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
  1. Setup a .env file with environment credentials

Single database environment:

DB_SERVER=
DB_PORT=
DB=
DB_SCHEMA=
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_SCHEMA=
PG_USER=
PG_PWD=

MS_SERVER=
MS_DB=
MS_SCHEMA=
MS_USER=
MS_PWD=

or

from sqlsorcery import MSSQL

conn = MSSQL(server="server_host", db="dba_name", schema="schema", user="username", pwd="password")

Examples

Query a table:

from sqlsorcery import MSSQL


conn = MSSQL()
df = conn.query("SELECT * FROM my_table")
print(df)

Query from a .sql file:

from sqlsorcery import MSSQL


conn = MSSQL()
df = conn.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)
conn = MSSQL()
conn.insert_into("table_name", df) 

Execute a stored procedure:

from sqlsorcery import MSSQL


conn = MSSQL()
conn.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.2.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

sqlsorcery-0.1.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file sqlsorcery-0.1.2.tar.gz.

File metadata

  • Download URL: sqlsorcery-0.1.2.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3

File hashes

Hashes for sqlsorcery-0.1.2.tar.gz
Algorithm Hash digest
SHA256 487676bba6b863b87f8ef556fa6e66f4dc02cfa64a4bd16028f816dd7cf71520
MD5 66309a2a30b364c9af9088b7959dd971
BLAKE2b-256 68696bcf7dd43fa923f53daefd62470dc1f249288b1e9f101d9947bdf85208e4

See more details on using hashes here.

File details

Details for the file sqlsorcery-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: sqlsorcery-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3

File hashes

Hashes for sqlsorcery-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ecef471b3a8c477a1a8f8febbd9bad75778871cb45f0c8feb9f7b6e5508c2953
MD5 ca3094fcd266e73058f9c83774d9c54b
BLAKE2b-256 d93623a65b634503619153b081480eab90fbbbea41bca354cdc5f5d385a6f9d4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page