All of the examples I've seen have used
COPY COMMAND | gzip > 'filename'
import gzip with gzip.open('table-data.gz', 'wb') as gzip_file: cursor.copy_to(gzip_file, 'my_table')
Alternatively, if you prefer to write text in certain encoding, and on Python 3.3+, you can use mode
'wt' and add
encoding='UTF-8' or similar to the