Is there a way to write a feature collection from Python memory to an S3 bucket (as Esri Shapefile, zipped Shapefile or something else) without writing it first to disk?

I tried writing to a ZipMemoryFile for later pushing it to s3 with boto3's upload_fileobj but it seems ZipMemoryFile are readonly

import fiona
from fiona.io import ZipMemoryFile
import boto3

# Initialize s3 client
s3 = boto3.client('s3')

# Read example feature collection
with fiona.open('fiona/tests/data/coutwildrnp.shp') as src:
    fc = list(src)
    meta = src.meta

# Write feature collection to file object
with ZipMemoryFile() as memfile:
    with memfile.open(path='test.shp', **meta) as dst:
        for feature in fc:

# Push to s3
s3.upload_fileobj(memfile, bucket, path)

The code above fails with a fiona.errors.DriverError: '/vsizip/vsimem/f588438c-3a3e-4f9c-80eb-c1f244911f96.zip/test.shp' does not exist in the file system, and is not recognized as a supported dataset name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.