Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 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 the boto3 library

Written by
Yandex Cloud
Updated at March 28, 2025

Follow this guide to connect to an S3 object storage in Jupyter Notebook using the boto3 library. To connect to an object storage, use an S3 connector:

Note

Avoid using S3 storage in FUSE mode for buckets with single-layer (non-recursive) folders that include many files, as this will significantly decrease storage performance.

To set up an S3 connection from the notebook code:

  1. Create the 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 relevant project in your community or on the DataSphere homepage 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 bucket name and retrieve a list of objects contained in it:

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

Was the article helpful?

Previous
Using file storages
Next
Connecting to a ClickHouse® database
© 2025 Direct Cursus Technology L.L.C.