Perhaps you could do this using a list of include patterns instead, and use --delete-excluded (which does as the name suggests)? Something like:
rsync -r --include-from=<patternlistfile> --exclude=* --delete-excluded / dest/
If filenames are likely to contain wildcard characters (*, ? and [) then you may need to modify the Python to escape them:
re.sub("([[*?])", r"\\\1", "abc[def*ghi?klm")
Edit: Pattern-based matching works slightly differently to --files-from in that rsync won’t recurse into directories that match the exclude pattern, for reasons of efficiency. So if your files are in /some/dir and /some/other/dir then your pattern file needs to look like:
/some/
/some/dir/
/some/dir/file1
/some/dir/file2
/some/other/
/some/other/dir/
/some/other/dir/file3
...
Alternatively, if all files are in the same directory then you could rewrite the command slightly:
rsync -r --include-from=<patternlistfile> --exclude=* --delete-excluded /some/dir/ dest/
and then your patterns become:
/file1
/file2
Edit: Thinking about it, you could include all directories with one pattern:
/**/
but then you’d end up with the entire directory tree in dest/ which probably isn’t what you want. But combining it with -m (which prunes empty directories) should solve that – so the command ends up something like:
rsync -m -r --delete-excluded --include-from=<patternfile> --exclude=* / dest/
and the pattern file:
/**/
/some/dir/file1
/some/other/dir/file3