# Tutorial: Uploading Files with Python Methods

Use a Python SDK to quickly upload large amounts of files. This method supports uploading metadata. It uses an open source SDK package.

***

- **Level**: Intermediate
- **Time to complete**: 10 minutes
- **Prerequisites**: 
  - You must be an Admin to complete this tutorial.
  - You need a basic knowledge of Python.
  - The workspace where you want to upload the files must already be created in <ProductName/>. In this tutorial, it's called `hotel_reviews`.
- **Goal**: After completing this tutorial, you will have uploaded a set of hotel reviews with metadata to a <ProductShortName/> workspace using a Python script. You can replace this dataset with your custom one. 

***

## Prepare Your Files

This tutorial uses a set of hotel reviews with some metadata in them. You can also use your own files; just make sure they have lowercase extensions, for example _myfile.txt_ instead of _myfile.TXT_.

1. Download [the hotel reviews dataset](https://drive.google.com/file/d/1T4ngb51UYIUIU1HVvEe4DzDzt4By0xSl/view?usp=sharing).
2. Extract the files to a folder called _hotel_reviews_ in your _Documents_ folder. This can take a couple of minutes.

**Result**: You have 5,956 files in the `_\Documents\hotel_reviews_` folder, 2978 TXT files and 2978 JSON files. Each TXT file is accompanied by a `.meta.json` file containing the text file metadata.

## Install the SDK

1. Open the command line and run:
   ```powershell
   pip install deepset-cloud-sdk
   ```
2. Wait until the installation finishes with a success message.

**Result**: You have installed the <ProductShortName/> SDK. It comes with a command line interface that we'll use to upload the files. 

## Obtain the API Key

1. Log in to [<ProductName/>](https://cloud.deepset.ai/).
2. Click your profile icon and choose _Connections_.
3. Under *API Keys*, click **Add new key**.
4. Choose the expiration date for your key and click **Generate key**.
5. Copy the key and save it to a notepad. 
6. Click **Done**.

**Result**: You have an API key saved in a file. You can now use it to upload your files. 

## Upload Files

1. Write a script that will upload the files from a specified path:
   1. In the same folder where you saved the _hotel_reviews_ files, create a Python script called `hotel_reviews_upload.py`. 
   2. Copy the code from the example below:
   ```python
   from pathlib import Path
   from deepset_cloud_sdk.workflows.sync_client.files import upload
   
   ## Uploads all files from a given path.
   upload(
    paths=[Path("<your_path_to_the_hotel_reviews_folder>")], # provide a path to the folder on your computer where you saved the hotel_reviews folder
    api_key="<your_deepset_api_key>", # the API key to connect to deepset
    workspace_name="<default_workspace>", # the workspace where you want to upload files
    blocking=True,  # waits until the files are displayed in deepset,
    # this may take a couple of minutes
    timeout_s=300,  # the timeout for the `blocking` parameter in number of seconds
    show_progress=True,  # shows the progress bar
    recursive=True,  # uploads files from all subfolders as well
    )

   ```

2. Save the script and run it: 
   ```python
   python hotel_reviews_upload.py
   ```
3. Wait until the upload finishes successfully. You should see this message:  

<ClickableImage
  src="/img/tutorials/finished_upload_sdk.png"
  alt="A console with a message informing about successful upload."
  size="standard"
/>

   5956 files are uploaded, and half of them, 2978, are listed in <ProductName/>. (The metadata files are not shown in <ProductShortName/>).

**Result**: You have uploaded all your files, including the ones from the subfolders. Let's now see if they're showing up in <ProductName/>.

## Verify the Upload

- In the command line, list the uploaded files by running: 

  <Tabs>
    <TabItem value="mac" label="macOS">
    
    ```python
    deepset-cloud list-files
    ```

    </TabItem>
    <TabItem value="windows" label="Windows">
    
    ```python
    python -m deepset_cloud_sdk.cli list-files
    ```

    </TabItem>
  </Tabs>

  You should see a list of files with file ID, URL, name, size, metadata, and the date when it was created. 

  <ClickableImage
    src="/img/tutorials/file_list.png"
    alt="A list of files with detailed information for each file."
    size="standard"
  />

  The number of files we uploaded makes it easier to verify if they uploaded correctly in the <ProductShortName/> UI.
- In <ProductName/>:

  1. Switch to the _hotel_reviews_ workspace where you uploaded the files and check the workspace statistics. You should see "3K" above files.  
  2. In the navigation, click **Files** and check if the files are showing on the Files page.

- Now, let's check if the metadata was uploaded:

  1. In the navigation, click **Files**.
  2. Click any file that has metadata and choose _View Metadata_. You should see the file's metadata.
