Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI for business
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex DataSphere
  • Getting started
    • All guides
      • Connecting to S3 using the boto3 library
      • Connecting to a ClickHouse® database
      • Connecting to a PostgreSQL database
      • Connecting to Yandex Disk
      • Connecting to Google Drive
    • Migrating a workflow to a new version
  • Terraform reference
  • Audit Trails events
  • Access management
  • Pricing policy
  • Public materials
  • Release notes
  1. Step-by-step guides
  2. Connecting to data sources
  3. Connecting to S3 using the boto3 library

Connecting to S3 using boto3

Written by
Yandex Cloud
Updated at August 15, 2025

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 mode for buckets with single-layer (non-recursive) folders that contain many files, as this will significantly degrade storage performance.

To set up an S3 connection from the notebook code:

  1. Create secrets: token (with ID) and key_value (with a secret part of the static access key for the service account).

  2. Open the DataSphere project:

    1. Select the project in your community or on the DataSphere home page in the Recent projects tab.

    2. Click Open project in JupyterLab and wait for the loading to complete.
    3. Open the notebook tab.
  3. Import the libraries:

    import boto3
    import os
    from os import path
    
  4. Enter the name of your bucket in the storage:

    bucket_name = '<bucket_name>'
    
  5. 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)
    
  6. Enter the name of the bucket and retrieve a list of objects it contains:

    for key in s3.list_objects(Bucket='<bucket_name>')['Contents']:
        print(key['Key'])
    

Was the article helpful?

Previous
File storage operations
Next
Connecting to a ClickHouse® database
© 2025 Direct Cursus Technology L.L.C.