Created
September 19, 2020 15:22
-
-
Save schnipdip/164ce5ec28b752726b1178300cb1d441 to your computer and use it in GitHub Desktop.
Constructing #Postgresql connection obect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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