Skip to main content

Dead simple wrapper for pandas and sqlalchemy

Project description

https://img.shields.io/badge/python-3.7-blue.svg https://img.shields.io/badge/license-MIT-green https://img.shields.io/static/v1?label=pipenv&message=latest&color=green

SQLSorcery: Dead simple wrapper for pandas and sqlalchemy

SQLSorcery is just some good old fashion syntactic sugar 🍬. It really doesn’t do anything new. It just makes doing it a little bit easier. It started as a connection wrapper for SQLAlchemy to cut down on the need for boilerplate code that was used to keep the database credentials secret, connect to the database, and then pass the connection to Pandas for queries and inserts.

It wasn’t much code, but needing to cut and paste it for each new project seemed like a recipe for bugs. So here we are. We’ve added more utility methods to the module as well as added all of the basic dialects of SQL that SQLAlchemy supports.

In many cases, the methods available are less robust than the underlying libraries and are more of a shortcut. When you need something that is outside the bounds of the defaults you can always drop back down into Pandas or SQLAlchemy to get more functionality/flexibility.

Getting Started

Install this library

$ pipenv install sqlsorcery

By default, sqlsorcery does not install the sql dialect specific python drivers. To install these, you can specify the dialects as a comma separated list of each dialect you will need drivers for.

$ pipenv install sqlsorcery[mssql]

OR

$ pipenv install sqlsorcery[mysql,postgres]

Setup .env file with credentials

For use with a single database:

DB_SERVER=
DB_PORT=
DB=
DB_SCHEMA=
DB_USER=
DB_PWD=

Otherwise, refer to the documentation for instructions.

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")

Documentation

Documentation and tutorials available at sqlsorcery.readthedocs.io

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.6.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlsorcery-0.1.6-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlsorcery-0.1.6.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.8

File hashes

Hashes for sqlsorcery-0.1.6.tar.gz
Algorithm Hash digest
SHA256 38ca3b4ff6bab8450e9daec54b5c326ee6903a67c5642a444cc91e0ee9a17829
MD5 a1e346218a8c3810cdd1fceae0f485b2
BLAKE2b-256 f5027dc0fe7d95c4cf2b3b542c3db0f3243e08e8e501b4673f6e3d4adf1f7e07

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlsorcery-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.8

File hashes

Hashes for sqlsorcery-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 be94b7740f3ffcef62cfd07f08c8bad802b9658cadc57f1835455b2dd801e0bf
MD5 c75858d78b1f469dc3f16189ec592ae9
BLAKE2b-256 f82506a171b026f2b719b2b70e14468163a1f90ee2f10eec7786750fa22cfddb

See more details on using hashes here.

Supported by

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