Create project using images urls

iPython Project Created 3 months ago Free
How to add remote images to Supervisely
Free Signup

Create Project with images by urls

A standart way to create new Project is to use Import page and upload pictures from hard drive. But this could cause troubles when you already have existing images on web server (i.e Amazon S3). Supervisely provides "Links" import plugin to add image to dataset without downloading any data - we just save link to remote image.

This cookbook implements the same functional. We will use popular movies posters from IMDB


  • List of image urls


  • New Project with images from input


Edit the following settings for your own case

In [1]:
import supervisely_lib as sly
import os
from slugify import slugify
from tqdm import tqdm
In [2]:
# Input urls

first_dataset_name = "dataset_01"
links_first_dataset = [

second_dataset_name = "dataset_02"
links_second_dataset = [

# Output Project
team_name = "jupyter_tutorials"
workspace_name = "cookbook"
project_name = "project_from_links"

# Obtain server address and your api_token from environment variables
# Edit those values if you run this notebook on your own PC
address = os.environ['SERVER_ADDRESS']
token = os.environ['API_TOKEN']
In [3]:
# Initialize API object
api = sly.Api(address, token)

Verify input values

Test that context (team / workspace / project) exists

In [4]:
# Get IDs of team and workspace

team =
if team is None:
    raise RuntimeError("Team {!r} not found".format(team_name))

workspace = api.workspace.get_info_by_name(, workspace_name)
if workspace is None:
    raise RuntimeError("Workspace {!r} not found".format(workspace_name))
print("Team: id={}, name={}".format(,
print("Workspace: id={}, name={}".format(,
Out [4]:
Team: id=30, name=jupyter_tutorials
Workspace: id=76, name=cookbook

Create empty Project

In [5]:
# check if project already exists. If yes - generate new free name
if api.project.exists(, project_name):
    project_name = api.project.get_free_name(, project_name)
# create remote project
project = api.project.create(, project_name)
print("Project: id={}, name={}".format(,
Out [5]:
Project: id=1324, name=project_from_links

Add remote images

We will use api.image.upload_link and api.image.add_link methods

In [6]:
for dataset_name, dataset_links in zip([first_dataset_name, second_dataset_name], [links_first_dataset, links_second_dataset]):
    dataset = api.dataset.create(, dataset_name)
    with tqdm(total=len(dataset_links), desc="Process links") as progress_bar:
        for links in sly.batched(dataset_links):
            names = []
            for link in links:
                # Get image name from url and slugify it
                image_name = slugify(sly.fs.get_file_name(link))
                image_ext = sly.fs.get_file_ext(link)
                names.append("{}{}".format(image_name, image_ext))

            # Add new images to dataset via links
            # We will retrieve some fields like MIME type or file size
            # Image itself won't be stored on our servers
            api.image.upload_links(, names, links)
Out [6]:
Process links: 100%|██████████| 3/3 [00:00<00:00, 126.63it/s]
Process links: 100%|██████████| 7/7 [00:00<00:00, 278.46it/s]
In [7]:
print("Project {!r} has been sucessfully uploaded".format(
print("Number of uploaded images: ", api.project.get_images_count(
Out [7]:
Project 'project_from_links' has been sucessfully uploaded
Number of uploaded images:  10

More Info

First released
3 months ago
Last updated
A month ago