Downloading Files From S3 in Python

In this tutorial, you will learn how to download files from S3 using the AWS Boto3 SDK in Python.

Boto3 SDK is a Python library for AWS. The Boto3 SDK provides methods for uploading and downloading files from S3 buckets.

You can also learn how to upload files to AWS S3 here.

Follow the steps below to upload download files from AWS S3:

Installing Boto3 AWS S3 SDK

Install the latest version of Boto3 S3 SDK using the following command:

pip install boto3

Downloading Files from S3

To download files from S3, use download_fileobj(bucket, key, filename) method that downloads a file as an object to a file-like object.


import boto3
from botocore.exceptions import ClientError

s3_client = boto3.client('s3', region_name='us-east-1', aws_access_key_id=ACCESS_KEY,

def download_my_file(bucket, folder, file_name):
    key = key = folder+"/"+file_name
    with open(file_name, 'wb') as f:
        s3_client.download_fileobj(bucket, key, f)

#Downloading file
download_my_file("bucket-name", "download-from-subfolder-name", "test.html")