Skip to content

Instantly share code, notes, and snippets.

View pythonreactor's full-sized avatar

Michael pythonreactor

View GitHub Profile
@tobywf
tobywf / boto3-gzip.py
Last active June 19, 2025 14:33
GZIP compressing files for S3 uploads with boto3
from io import BytesIO
import gzip
import shutil
def upload_gzipped(bucket, key, fp, compressed_fp=None, content_type='text/plain'):
"""Compress and upload the contents from fp to S3.
If compressed_fp is None, the compression is performed in memory.
"""