# Exporting images and annotations using SDK

**URL:** <https://community.labelstud.io/t/exporting-images-and-annotations-using-sdk/233>\
**Category:** Label Studio SDK\
**Created:** [June 4, 2024, 3:12am UTC](https://community.labelstud.io/t/exporting-images-and-annotations-using-sdk/233 "2024-06-04T03:12:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![sajarin](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.labelstud.io/sajarin/32/56_2.png) [@sajarin](https://community.labelstud.io/u/sajarin)\
**Post date:** [June 4, 2024, 4:38pm UTC](https://community.labelstud.io/t/exporting-images-and-annotations-using-sdk/233/2 "2024-06-04T16:38:55Z")

</div>

Hey @ras, thanks for the question!

To export annotations along with images in YOLO format using the Label Studio SDK, you can follow these steps:

1. **Ensure Images are Accessible** : Make sure that the images are accessible from the location where the SDK is running. If the images are stored in cloud storage, ensure that the SDK has access to download them.
2. **Use the export\_snapshot\_create and export\_snapshot\_download Methods** : These methods allow you to create an export snapshot and download it. However, by default, the images might not be included. You need to ensure that the download\_resources parameter is set to True.

Here is an rough script to achieve this:

```auto
import os
import time
from label_studio_sdk import Client

# Define the URL where Label Studio is accessible and the API key for your user account
LABEL_STUDIO_URL = 'http://your-label-studio-url'
API_KEY = 'your_api_key'

# Connect to the Label Studio API
ls = Client(url=LABEL_STUDIO_URL, api_key=API_KEY)
ls.check_connection()

PROJECT_ID = 1
EXPORT_TYPE = 'YOLO'

# Get the project
project = ls.get_project(PROJECT_ID)

# Create an export snapshot
export_result = project.export_snapshot_create(
    title='export-test-01',
    task_filter_options={
        'view': 1,
        'finished': 'only', # include all finished tasks (is_labeled = true)
        'annotated': 'only', # include all tasks with at least one not skipped annotation
    }
)
export_id = export_result['id']

# Wait until the snapshot is ready
while project.export_snapshot_status(export_id).is_in_progress():
    time.sleep(1.0)

# Download the snapshot
status, zip_file_path = project.export_snapshot_download(
    export_id=export_id,
    export_type=EXPORT_TYPE,
    path='.',
    download_resources=True # Ensure resources (images) are downloaded
)

print(f'Status of the export is {status}.\nFile path is {zip_file_path}')

```

### Important Notes:

- **Environment Variables** : Ensure that the environment variable CONVERTER\_DOWNLOAD\_RESOURCES is set to 1 if you are running Label Studio in an environment where this is required.

- **Local Storage** : If you are using local storage, ensure that the LS\_UPLOAD\_DIR environment variable is set correctly to point to the directory where images are stored.

### Troubleshooting:

- **Empty Image Folder** : If the image folder in the exported zip is empty, double-check the paths and permissions to ensure that the SDK can access and download the images.

- **Timeouts** : For large datasets, exporting might take a long time. Ensure that your server settings allow for sufficient timeout periods.

If you encounter any issues or need further assistance, feel free to ask!

---

_[View the full topic](https://community.labelstud.io/t/exporting-images-and-annotations-using-sdk/233)._
