I'm writing a Python script that will connect to a postgresql database using the psycopg2 library. I'm getting around it pretty well but one concern I have is that when connecting to the database host, I have to hard code the username and password into the connection statement. I would prefer not to do this and would like to somehow refer to an external file for this information and import that user account info then construct the connection string. That way at least the username/password combo wouldn't be directly visible when looking at the Python code. Any help or alternative ideas would be very much appreciated.
Example of the psycopg2 connection statement:
conn_string = "dbname='mydatabase' port='1234' user='joe_shmoe' password = 'joespassword' host='hostaddress.com'"
conn = psycopg2.connect(conn_string)