Use getpass.getpass()
:
from getpass import getpass
password = getpass()
An optional prompt can be passed as parameter; the default is "Password: "
.
Note that this function requires a proper terminal, so it can turn off echoing of typed characters – see “GetPassWarning: Can not control echo on the terminal” when running from IDLE for further details.