I am using a Python script with the pysftp module to connect to SFTP server.  
Apparently I can pass a SFTP password explicitly which I don't like.
My question: How could I replace the password for an encrypted one to avoid someone from being visible to the world?
Do you mean you do not want the password to be visible in code or configuration file? There's no way to encrypt anything in a way that allows automatic decryption. All you can do is to obfuscate the password, but not really encrypt it. If anyone can access your code he/she can always reverse-engineer your "encryption".
How to encrypt password in Python pysftp?