I needed this for something where I wanted to send the visitor of a website a bunch of files he selected at once. An easy way to do this would be to add the files to a zip file and then send that zip file to the user. Unfortunately Python doesn’t have an in-memory zip file library, you can only interact with zip files on disk.
After a bit of googling around I came to this StackOverflow answer. That worked like a charm, and here is my more reusable version:
Save as “inmemoryzip.py” and import it as “inmemoryzip”. This is quite limited compared to the standard ZipFile class, but this gets the job done for what I needed it.