How to use rsync from within a python script? [closed]

Solution 1:

import os
os.system("rsync -avrz /opt/data/filename root@ip:/opt/data/file")

Did you try that?
os.system basically allows you to run bash commands.

Solution 2:

As the answer to your previous similar question suggests, rsync will work just fine as a shell command from within Python if you use SSH keys to authenticate instead of a password. If you need further help with how to set up SSH key-based authentication, please edit your question.