I stumbled upon this thread while I was trying to preform the same feat. I know this thread is old, but if anyone else needs this - here is how I did it.
I ended up using readchar package.
Here is my solution, it prints asterisks and also handles backspaces:
import sys, readchar
def passprompt(prompt: str, out = sys.stdout) -> str:
out.write(prompt); out.flush()
password = ""
while True:
ch = str(readchar.readchar(), encoding='UTF-8')
if ch == '\r':
break
elif ch == '\b':
out.write('\b \b')
password = password[0:len(password)-1]
out.flush()
else:
password += ch
out.write('*')
out.flush()
return password
I had to regularly flush stdout for it to work.