Filenames and ReadURLs

Filenames

As you already saw in the Export Filenames section, you can easily export filenames of a dataset in the LightlyOne Platform with the following code snippet:

from lightly.api import ApiWorkflowClient

# Create the LightlyOne client to connect to the API.
client = ApiWorkflowClient(token="MY_LIGHTLY_TOKEN", dataset_id="MY_DATASET_ID")

filenames = client.export_filenames_by_tag_name(
    tag_name="initial-tag"  # name of the tag in the dataset
)
with open("filenames-of-initial-tag.txt", "w") as f:
    f.write(filenames)

The output file will look similar to the example below:

your-image-1.png
your-image-2.png
...

ReadURLs

It is also possible to export filenames together with readURLs. A readURL allows you to access an image anywhere and anytime. This is especially useful if you want to grant access to the selected images to a team member or a third party, such as a labeling company. Use the following code to get a JSON object mapping filenames to readURLs:

import json
from lightly.api import ApiWorkflowClient

# Create the LightlyOne client to connect to the API.
client = ApiWorkflowClient(token="MY_LIGHTLY_TOKEN", dataset_id="MY_DATASET_ID")

filenames_and_read_urls = client.export_filenames_and_read_urls_by_tag_name(
    tag_name="initial-tag"  # name of the tag in the dataset
)
with open("filenames-and-read-urls.json", "w") as f:
    json.dump(filenames_and_read_urls, f, indent=4)

The output file will look similar to the example below:

[
    {
        "fileName": "your-image.png",
        "readUrl": "https://your-bucket.provider.com/your-image.png"
    },
    ...
]