Skip to main content

Simplify SQL Connection for data analysis

Project description

Simplify Connection to your Database

Simple Connect allows you to securely access your database and it supports SSH Connection Currently it only supports SQL Databses.

Sample Usage

from simple_connect import connect

conn = connect.Connect('sample_credential.json', 'database_name')

sample_table = conn.query('SELECT * FROM sample_table')

Installation

pip install simple-connect

Secure your Database credentials

This step is optional.

Simple Connect tries to find your database / ssh credentials from a json file in ".credentials" folder which is in your home directory. Example for windows, mac and linux respectively:

C:\Users\John\.credentials\sample.json

/Users/John/.credentials/sample.json

/home/John/.credentials/sample.json

Create the json file.

Json file should be in your following format:

{
  "SQL_HOST": "host_example<127.0.0.1>",
  "SQL_USER": "<username_of_your_sql>",
  "SQL_PASSWORD": "<password_of_your_sql>"
}

For SSH, you'll need to add additional keys:

{
  "SSH_USERNAME": "<ssh_username>",
  "SSH_PASSWORD": "<ssh_password>",
  "BASTION_HOST": "<sshBastion_host>"
  "SQL_HOST": "host_example<127.0.0.1>",
  "SQL_USER": "<username_of_your_sql>",
  "SQL_PASSWORD": "<password_of_your_sql>"
}

Usage

Import

from simple_connect import connect

Basic connection:

conn = connect.Connect('sample_credential.json', 'database_name')

OR you can give the etire path of the json file:

conn = connect.Connect('C:\Users\John\.credentials\sample.json', 'database_name')

SSH connection:

conn = connect.BastionConnect('sample_credential.json', 'database_name')

OR if you want to use your own ssh key:

conn = connect.BastionConnect('sample_credential.json', 'database_name', 'ssh_key.pem')

Querying

Read

Query table (returns pandas dataframe):

sample_table = conn.query('SELECT * FROM sample_table')

For Insert, Update and Delete -> Give dataframe rows that are required to update in table.

Insert

Insert new table or append to existing table:

conn.to_db(dataframe, '<table_name>')

Update

conn.update_table(dataframe, 'table_name', ['column_to_set1', 'column_to_set2', ...], ['columns_where_contition_applies', ...])

Example:

SQL:
UPDATE sample_table SET student = 'john', class = 5 WHERE id = 432 AND id_2 = 'SC'
UPDATE sample_table SET student = 'alisha', class = 5 WHERE id = 525 AND id_2 = 'SC'

Python:
conn.update_table(dataframe, 'sample_table', ['student', 'class'], ['id', 'id_2'])

Delete

conn.delete_row(dataframe, 'table_name', ['columns_where_contition_applies', ...])

Example:

conn.delete_row(dataframe, 'sample_table', ['id', 'id_2'])

Execute SQL statement

conn.execute(query)

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

simple_connect-1.1.1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

simple_connect-1.1.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file simple_connect-1.1.1.tar.gz.

File metadata

  • Download URL: simple_connect-1.1.1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.0

File hashes

Hashes for simple_connect-1.1.1.tar.gz
Algorithm Hash digest
SHA256 aa96bf14d9a70827fbe4d6a7c2cbdcc844f6b3c34fcbb3b51db877a20d3483bb
MD5 e0fb4294095ea47003d5b7c78c375b06
BLAKE2b-256 6443b8691e84745c5d44f1b0edbf404b42f08468d1dc52aff7fa116b7db36fdf

See more details on using hashes here.

File details

Details for the file simple_connect-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: simple_connect-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.0

File hashes

Hashes for simple_connect-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b07a6e4faeeb8ce0169a55838f17ae34ff263d13b864db105b5909675f5298f6
MD5 0f11c5a925de8b4f3b035f2e2e17184c
BLAKE2b-256 86a7add2213c6c4e13cb49816b085b761a166d5cf5bb98a7c8f3d168f367e5b8

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