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
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 directory and 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')
SSH connection:
conn = connect.BastionConnect('sample_credential.json', 'database_name')
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'])
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_connect-1.1.0.tar.gz.
File metadata
- Download URL: simple_connect-1.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f237bbbd36100eff6eb5c64ada7a4304038791a7da06ae85cc53749a875f24c4
|
|
| MD5 |
97fd009a4f528eaeb93eac18e43ce878
|
|
| BLAKE2b-256 |
78a19824a3a252e1ce1b85121d2771c70d45752f99f53888bceb5d9821e3f872
|
File details
Details for the file simple_connect-1.1.0-py3-none-any.whl.
File metadata
- Download URL: simple_connect-1.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84b76ccfcf03fa1743c96c2743b9b0fc56c5ab106661f53a187cc20bacc92b73
|
|
| MD5 |
387ecdab06e57aac71de874208f18165
|
|
| BLAKE2b-256 |
11bf0bdd2eedd01414787f0789b083c4ea60507fcc3a9f7767bf1175a578e03e
|