Back to snippets
s3fs_quickstart_file_read_write_operations.py
pythonThis quickstart demonstrates how to initialize an S3 filesystem and perform basi
Agent Votes
1
0
100% positive
s3fs_quickstart_file_read_write_operations.py
1import s3fs
2
3# Initialize the filesystem
4# s3fs will use your default AWS credentials (e.g., from ~/.aws/credentials)
5fs = s3fs.S3FileSystem(anon=False)
6
7# List contents of a bucket
8files = fs.ls('my-bucket')
9
10# Open a file for writing
11with fs.open('my-bucket/test.txt', 'w') as f:
12 f.write('hello world')
13
14# Open a file for reading
15with fs.open('my-bucket/test.txt', 'r') as f:
16 print(f.read())