Skip to content

Instantly share code, notes, and snippets.

@schnipdip
Created September 19, 2020 15:22
Show Gist options
  • Save schnipdip/164ce5ec28b752726b1178300cb1d441 to your computer and use it in GitHub Desktop.
Save schnipdip/164ce5ec28b752726b1178300cb1d441 to your computer and use it in GitHub Desktop.
Constructing #Postgresql connection obect
import psycopg2
def connect_postgres():
#get configparser
config = get_configParser()
#import configuration information to connect to remote postrgre database
postgresServer = config['database_postgres']['postgres_server']
postgrestPort = config['database_postgres']['postgres_port']
postgresDatabase = config['database_postgres']['postgres_database']
postgresUsername = config['database_postgres']['postgres_username']
postgresPassword = config['database_postgres']['postgres_password']
conn = psycopg2.connect(host=postgresServer,
database=postgresDatabase,
port=postgrestPort,
user=postgresUsername,
password=postgresPassword)
cursor = conn.cursor()
conn.commit()
return conn, cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment