Skip to main content

Simplify Connection

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

simple_connect-1.0.4.tar.gz (6.6 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.0.4-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_connect-1.0.4.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for simple_connect-1.0.4.tar.gz
Algorithm Hash digest
SHA256 80da40ab50f21f4fb5111496f8e9150deaecb25cd9a0441e0936142bb1f5e785
MD5 df8e3d48d580e7d7607f9553e7bd774f
BLAKE2b-256 48fb7931cf40b970c579315a3492bda83734d40803ddb83d0124bcb25945caeb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simple_connect-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for simple_connect-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 aca4182a2ae762dff82945ad0e4acbb6e83f981899805e37d3373eb8ff503c5d
MD5 3164807e8508aac081f50ade1af40808
BLAKE2b-256 8894ce0572dec8a93be5df3a3833167fc15fdb0e94392cf986c0e5c966b73cfe

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