[Yandex Cloud documentation](../../../index.md) > [Yandex DataSphere](../../index.md) > [Step-by-step guides](../index.md) > Connecting to data sources > Connecting to S3 using boto3

# Connecting to S3 using boto3

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](s3-connectors.md):

{% note info %}

Avoid using your S3 storage in [FUSE](https://en.wikipedia.org/wiki/Filesystem_in_Userspace) mode for buckets with single-layer (non-recursive) folders that contain many files, as this will significantly degrade storage performance.

{% endnote %}

To set up an S3 connection from the notebook code:

1. [Create secrets](secrets.md#create): `token` (with ID) and `key_value` (with a secret part of the [static access key](../../../iam/operations/authentication/manage-access-keys.md#create-access-key) for the service account).
1. Open the DataSphere project:
   
   1. Select the project in your community or on the DataSphere [home page](https://datasphere.yandex.cloud) in the **Recent projects** tab.
   1. Click **Open project in JupyterLab** and wait for the loading to complete.
   1. Open the notebook tab.
1. Import the libraries:

    ```python
    import boto3
    import os
    from os import path
    ```

1. Enter the name of your bucket in the storage:

    ```python
    bucket_name = '<bucket_name>'
    ```

1. Establish a connection:

    ```python
    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)
    ```

1. Enter the name of the bucket and retrieve a list of objects it contains:

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