psycopg2
will never prompt for a password - that's a feature of psql
, not of the underlying libpq
that both psql
and psycopg2
use. There's no equvialent of -w
/ -W
because there's no password prompt feature to turn on/off.
If you want to prompt for a password you must do it yourself in your code: trap the exception thrown when authentication fails because a password is required, prompt the user for a password, and reconnect using the password. That's what psql
does anyway, if you take a look at the sources.