# Manage datasets and files

> Use the Python SDK to efficiently create, manage, download, and organize datasets and files in Unity Asset Manager.

## Before you begin

To access any datasets, make sure the app has the right accesses. Read more about [managing Identity](/asset-manager/python-sdk/manage-identity.md).

> **Note:**
>
> The following code snippets first require an initialization. To learn more about the `initialize()` and `uninitialize()` methods, read about [getting started with the Unity Cloud Python SDK](/asset-manager/python-sdk/get-started.md).

## How do I...?

### Create a dataset

To add a dataset to an already existing asset, call `create_dataset` with the required information.

This method returns the dataset id as a string.

```python
    dataset_id = unity_cloud.assets.create_dataset(
        org_id = "012345678912",
        project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
        asset_id = "0123456789abcdefghijklmn",
        asset_version = "1234abcd-ab12-cd34-ef56-123456abcdef",
        dataset_name = "your-new-dataset-name"
    )
```

### Update a dataset

To update a dataset name, description, tags, or file order, follow these steps:

1. Create a `DatasetUpdate` object.
2. Call the `update_dataset` method.

```python
    dataset_update = DatasetUpdate(
        name = "your-dataset-name",
        description = "your-dataset-description",
        tags = ["your-tag-1", "your-tag-2", "your-tag-3"],
        file_order = ["your_file_1.ext", "your_file_2.ext", "your_file_3.ext"]
    )
    unity_cloud.assets.update_dataset(
        dataset_update = dataset_update,
        org_id = "012345678912",
        project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
        asset_id = "0123456789abcdefghijklmn",
        asset_version = "1234abcd-ab12-cd34-ef56-123456abcdef",
        dataset_id = "1234abcd-12ab-34cd-56ef-123456abcdef"
    )
```

### Get a dataset

To fetch a specific dataset, call the `get_dataset` method.

```python
    dataset = unity_cloud.assets.get_dataset(
        org_id = "012345678912",
        project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
        asset_id = "0123456789abcdefghijklmn",
        asset_version = "1234abcd-ab12-cd34-ef56-123456abcdef",
        dataset_id = "1234abcd-12ab-34cd-56ef-123456abcdef"
    )
```

### Get a list of all datasets within an asset

To fetch all datasets contained in a given asset, call the `get_dataset_list` method.

```python
    datasets = unity_cloud.assets.get_dataset_list(
        org_id = "012345678912",
        project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
        asset_id = "0123456789abcdefghijklmn",
        asset_version = "1234abcd-ab12-cd34-ef56-123456abcdef"
    )
```

### Upload a local file to a dataset

To add a file to any dataset contained in your asset, follow these steps:

1. Create an `AssetFileUploadInformation` object.
2. Call the `upload_file` method.
3. (Optional) Pass the `upload_file` method to track the progress via callback.

> **Note:**
>
> The `AssetFileUploadInformation.UploadFilePath` field stores the location of the file you want to upload. The `AssetFileUploadInformation.CloudFilePath` field stores the desired file path of the file on the Asset Manager and should be passed as `PurePosixPath`.

```python
    from pathlib import PurePath, PurePosixPath

    def show_upload_progress(progress):
        print(progress)

    upload_asset = FileUploadInformation(
        organization_id = "012345678912",
        project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
        asset_id = "0123456789abcdefghijklmn",
        asset_version = "1234abcd-ab12-cd34-ef56-123456abcdef",
        dataset_id = "1234abcd-12ab-34cd-56ef-123456abcdef",
        upload_file_path = PurePath("computer/path/to/file.ext"),
        cloud_file_path = PurePosixPath("path/to/file.ext")
    )

    unity_cloud.assets.upload_file(
        asset_upload_information = upload_asset,
        progress_callback = show_progress
    )
```

### Update a file's metadata

To update the description and the tags of a file, follow these steps:

1. Create an `AssetFileUpdate` object.
2. Call the `update_file` method.

The `file_path` argument in the `update_file` method must correspond with the cloud file path used when uploading the file.

```python
    from pathlib import PurePosixPath

    asset_file_update = FileUpdate(
        description = "your-file-description",
        tags = ["your-tag-1", "your-tag-2", "your-tag-3"]
    )

    unity_cloud.assets.update_file(
        asset_file_update = asset_file_update,
        org_id = "012345678912",
        project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
        asset_id = "0123456789abcdefghijklmn",
        asset_version = "1234abcd-ab12-cd34-ef56-123456abcdef",
        dataset_id = "1234abcd-12ab-34cd-56ef-123456abcdef",
        cloud_file_path = PurePosixPath("path/to/file.ext")
    )
```

### Download a file contained in a dataset

To download a file, follow these steps:

1. Create an `AssetFileDownloadInformation` object with `FilePath`. `FilePath` indicates the file the path in Asset Manager and `DownloadFolderPath` indicates the destination for the downloaded on your computer.
2. Call the `download_file` method.
3. (Optional) Pass the `download_file` method to track the progress via callback.

```python
    def show_download_progress(progress):
        print(progress)

    asset_file_download_infos = FileDownloadInformation(
        organization_id = "012345678912",
        project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
        asset_id = "0123456789abcdefghijklmn",
        asset_version = "1234abcd-ab12-cd34-ef56-123456abcdef",
        dataset_id = "1234abcd-12ab-34cd-56ef-123456abcdef",
        cloud_file_path = PurePosixPath("path/to/file.ext"),
        download_folder_path = PurePath("path/to/folder")
    )

    unity_cloud.assets.download_file(
        asset_download_information = asset_file_download_infos,
        progress_callback = show_download_progress
    )
```

### Get a file

To fetch a specific file, call `get_file`.

```python
    files = unity_cloud.assets.get_file_list(
        org_id = "012345678912",
        project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
        asset_id = "0123456789abcdefghijklmn",
        asset_version = "1234abcd-ab12-cd34-ef56-123456abcdef",
        dataset_id = "1234abcd-12ab-34cd-56ef-123456abcdef",
        cloud_file_path = PurePosixPath("path/to/file.ext")
    )
```

### Get a list of all files within a dataset

To fetch all files contained in a given dataset, call `get_file_list`.

```python
    files = unity_cloud.assets.get_file_list(
        org_id = "012345678912",
        project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
        asset_id = "0123456789abcdefghijklmn",
        asset_version = "1234abcd-ab12-cd34-ef56-123456abcdef",
        dataset_id = "1234abcd-12ab-34cd-56ef-123456abcdef"
    )
```

### Remove a file from a dataset

To remove a file from a dataset, call `unity_cloud.assets.remove_file`.

```python
    from pathlib import PurePosixPath

    unity_cloud.assets.remove_file(
        org_id = "012345678912",
        project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
        asset_id = "0123456789abcdefghijklmn",
        asset_version = "1234abcd-ab12-cd34-ef56-123456abcdef",
        dataset_id = "1234abcd-12ab-34cd-56ef-123456abcdef",
        file_path = PurePosixPath("path/to/file.ext")
    )
```

### Get a list of suggested generated tags for a picture file

To get a list of suggested tags for a picture file, call `get_suggested_tags`. They are generated based on the content of the image.

```python
    suggested_tags = unity_cloud.assets.generate_suggested_file_tags(
        org_id = "012345678912",
        project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
        asset_id = "0123456789abcdefghijklmn",
        asset_version = "1234abcd-ab12-cd34-ef56-123456abcdef",
        dataset_id = "1234abcd-12ab-34cd-56ef-123456abcdef",
        file_path = PurePosixPath("path/to/file.ext")
    )
```
