Skip to content

Instantly share code, notes, and snippets.

@statguy
Last active February 10, 2022 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statguy/f92b8fc08211b232c4ae77ca8662a704 to your computer and use it in GitHub Desktop.
Save statguy/f92b8fc08211b232c4ae77ca8662a704 to your computer and use it in GitHub Desktop.
Write pickle to and read from S3 and local file system
from typing import Any
import fsspec
import pickle
def write_pickle(data: Any, path: str) -> None:
with fsspec.open(path, "wb") as file:
pickle.dump(data, file)
def read_pickle(path: str) -> Any:
with fsspec.open(path, "rb") as file:
return pickle.load(file)
data = {"a": 1}
write_pickle(data, "s3://my_bucket/data.tmp")
write_pickle(data, "file:///tmp/data.tmp")
assert read_pickle("s3://my_bucket/data.tmp") == data
assert read_pickle("file:///tmp/data.tmp") == data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment