Use paramiko to replace bare calls to /usr/bin/ssh (also see: Fabric)
Paramiko provides functionality for remote connections,
Comments from @tim.schoof on !1 (merged): "... [it] could be used instead of calling the external ssh
command. There is also https://docs.fabfile.org/en/2.6/getting-started.html which could be used or at least provide some ideas."