Alter postgres password from python?
You have two options when running code from Python,


Python has a method called autocommit you either have to turn this on, 
or, you have to run a manual COMMIT; after you issue the command.


Without either of those the command will automatically ROLLBACK;

answer inspired by @a_horse_with_no_name in the comments