Connecting to S3 using boto3
Written by
Updated at October 30, 2026
Follow this guide to connect to an S3 object storage in Jupyter Notebook using boto3. To connect to an object storage, use an S3 connector:
Note
Avoid using your S3 storage in FUSE
To set up an S3 connection from the notebook code:
-
Create secrets:
token(with ID) andkey_value(with a secret part of the static access key for the service account). -
Open the DataSphere project:
-
Select the project in your community or on the DataSphere home page
in the Recent projects tab. - Click Open project in JupyterLab and wait for the loading to complete.
- Open the notebook tab.
-
-
Import the libraries:
import boto3 import os from os import path -
Enter the name of your bucket in the storage:
bucket_name = '<bucket_name>' -
Establish a connection:
session = boto3.session.Session() ENDPOINT = "https://storage.yandexcloud.net" session = boto3.Session( aws_access_key_id=(os.environ['token']), aws_secret_access_key=(os.environ['key_value']), region_name="ru-central1", ) s3 = session.client( "s3", endpoint_url=ENDPOINT) -
Get a list of objects in the bucket:
paginator = s3.get_paginator('list_objects_v2') for page in paginator.paginate(Bucket='<bucket_name>'): for key in page.get('Contents', []): print(key['Key'])