Going Passwordless
In addition to everything mentioned so far, it is also a good idea to set up a .pgpass file. A .pgpass file specifies the parameters that you use to connect to your database, including your password. All of the programmatic methods of accessing the database discussed in this chapter (using either psql or Python) will allow you to skip the password parameter if your .pgpass file contains the password for the matching hostname, database, and username. This not only saves you time but also increases the security of your database because you can freely share your code without having to worry about passwords embedded in the code.
On Unix-based systems and macOS, you can create the .pgpass file in your home directory. On Windows, you can create the file in %APPDATA%\postgresql\pgpass.conf. %APPDATA% is a Windows system value that points to the current application data folder. You can get the actual value of it by opening Windows Explorer, typing the exact word %APPDATA...