Read and write in the cloud#

shapelib treats cloud paths as first-class citizens: read_file and save accept S3 and HTTPS locations directly, so pipelines don’t need manual download/upload steps.

With presigned URLs#

Presigned URLs carry their own credentials — nothing to configure. This is the common case inside GeoIA services:

from shapelib import read_file

lines = read_file("https://bucket.s3.amazonaws.com/lines.fgb?X-Amz-Signature=...")

# ... process ...

lines.save("https://bucket.s3.amazonaws.com/output.fgb?X-Amz-Signature=...")

With the s3:// protocol#

For direct bucket access, set the AWS credentials in the environment (AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY):

lines = read_file("s3://my-bucket/data/lines.gpkg")
lines.save("s3://my-bucket/outputs/lines_clean.fgb")

Choosing the format#

Cloud-friendly formats (.fgb, .geojson, .gpkg) are streamed with range requests — reading a subset of a large file doesn’t download all of it. .shp, .kml and .sqlite are downloaded to a temporary file first.

Tip

For data that lives in S3, prefer FlatGeobuf (.fgb): it streams, it’s a single file, and it round-trips through shapelib without schema surprises.