You can take a look at aesfile : https://github.com/bibi21000/AesFile
To encrypt :
import aesfile
with open(source, 'rb') as fin, aesfile.open(destination, mode='wb', aes_key=key) as fout:
while True:
data = fin.read(7777)
if not data:
break
fout.write(data)
And decrypt :
import aesfile
with aesfile.open(source, mode='rb', aes_key=key) as fin, open(destination, 'wb') as fout :
while True:
data = fin.read(8888)
if not data:
break
fout.write(data)
Or you can compress (with zstd) and encrypt in one pass, simply replace
import aesfile
with
import aesfile.zstd
Look at https://github.com/bibi21000/CofferFile/blob/main/BENCHMARK.md for performance impact.