StorageApi

class StorageApi(api)[source]

Bases: FileApi

API for working with files and folders in Team Files and Cloud Storage.

Parameters:
api

Api object to use for API connection.

Usage Example:
import supervisely as sly
api = sly.Api.from_env()
files = api.storage.list(team_id, file_path)

Methods

convert_info_to_json

Convert information about an entity to a dictionary.

dir_exists

Checks if directory exists in Team Files / Cloud Storage / Agent.

download

Download File from Team Files.

download_async

Download File from Team Files.

download_bulk_async

Download multiple Files from Team Files.

download_directory

Download Directory from Team Files.

download_directory_async

Download Directory from Team Files to local path asynchronously.

download_from_agent

download_input

Downloads data for application from input using environment variables.

download_input_async

Asynchronously downloads data for the application, using a path from file/folder selector.

exists

Checks if file exists in Team Files / Cloud Storage / Agent.

get_directory_size

Get directory size in the Team Files.

get_free_dir_name

Adds suffix to the end of the Directory name.

get_free_name

Adds suffix to the end of the file name.

get_info_by_id

This method available only for Team Files.

get_info_by_path

Gets File information by path in Team Files / Cloud Storage / Agent.

get_json_file_content

Get JSON file content.

get_list_all_pages

Get list of all or limited quantity entities from the Supervisely server.

get_list_all_pages_generator

This generator function retrieves a list of all or a limited quantity of entities from the Supervisely server, yielding batches of entities as they are retrieved

get_list_idx_page_async

Get the list of items for a given page number.

get_list_page_generator_async

Yields list of images in dataset asynchronously page by page.

get_url

info_sequence

Sequence of fields that are returned by the API to represent FileInfo.

info_tuple_name

Name of the tuple that represents FileInfo.

is_on_agent

list

List of all or limited quantity files from the Team Files or Cloud Storages.

list2

Method is not implemented.

list_on_agent

List of files in the Team Files.

listdir

Method is not implemented.

load_dotenv_from_teamfiles

Loads .env file from Team Files into environment variables.

parse_agent_id_and_path

remove

Removes a file from the Team Files.

remove_batch

Removes list of files from Team Files.

remove_dir

remove_file

Removes file from Team Files.

remove_from_agent

rename

Renames file in Team Files

upload

Upload File to Team Files.

upload_async

Upload file from local path to Team Files asynchronously.

upload_bulk

Upload Files to Team Files.

upload_bulk_async

Upload multiple files from local paths to Team Files asynchronously.

upload_bulk_fast

Upload multiple files from local paths to Team Files in fast mode.

upload_directory

Upload Directory to Team Files from local path.

upload_directory_async

Upload Directory to Team Files from local path.

upload_directory_fast

Upload Directory to Team Files from local path in fast mode.

Attributes

MAX_WAIT_ATTEMPTS

Maximum number of attempts that will be made to wait for a certain condition to be met.

WAIT_ATTEMPT_TIMEOUT_SEC

Number of seconds for intervals between attempts.

InfoType

alias of FileInfo

classmethod convert_info_to_json(info)

Convert information about an entity to a dictionary.

Parameters:
info : NamedTuple

Information about the entity.

Returns:

Dictionary with information about the entity.

Return type:

dict

static info_sequence()

Sequence of fields that are returned by the API to represent FileInfo.

Usage Example:
FileInfo(
    team_id=8,
    id=7660,
    user_id=7,
    name='00135.json',
    hash='z7Hv9a7WIC5HIJrfX/69KVrvtDaLqucSprWHoCxyq0M=',
    path='/999_App_Test/ds1/00135.json',
    storage_path='/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json',
    mime='application/json',
    ext='json',
    sizeb=261,
    created_at='2021-01-11T09:04:17.959Z',
    updated_at='2021-01-11T09:04:17.959Z',
    full_storage_url='http://supervisely.com/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json'
)
static info_tuple_name()

Name of the tuple that represents FileInfo.

dir_exists(team_id, remote_directory)[source]

Checks if directory exists in Team Files / Cloud Storage / Agent.

Parameters:
team_id : int

Team ID in Supervisely.

remote_path : str

Remote path to directory in Team Files.

Returns:

True if directory exists, otherwise False

Return type:

bool

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

file = api.storage.dir_exists(8, "/999_App_Test/")   # True
file = api.storage.dir_exists(8, "/10000_App_Test/") # False
download(team_id, remote_path, local_save_path, cache=None, progress_cb=None)

Download File from Team Files.

Parameters:
team_id : int

Team ID in Supervisely.

remote_path : str

Path to File in Team Files.

local_save_path : str

Local save path.

cache=None

optional

progress_cb : tqdm or callable, optional

Function for tracking download progress.

Returns:

None

Return type:

None

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

path_to_file = "/999_App_Test/ds1/01587.json"
local_save_path = "/home/admin/Downloads/01587.json"

api.file.download(8, path_to_file, local_save_path)
async download_async(team_id, remote_path, local_save_path, semaphore=None, cache=None, progress_cb=None, progress_cb_type='size')

Download File from Team Files.

Parameters:
team_id : int

Team ID in Supervisely.

remote_path : str

Path to File in Team Files.

local_save_path : str

Local save path.

semaphore : asyncio.Semaphore

Semaphore for limiting the number of simultaneous downloads.

cache=None

Cache object for storing files.

progress_cb : tqdm or callable, optional

Function for tracking download progress.

progress_cb_type : Literal["number", "size"], optional

Type of progress callback. Can be “number” or “size”. Default is “size”.

Returns:

None

Return type:

None

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

path_to_file = "/999_App_Test/ds1/01587.json"
local_save_path = "/path/to/save/999_App_Test/ds1/01587.json"
loop = sly.utils.get_or_create_event_loop()
loop.run_until_complete(api.file.download_async(8, path_to_file, local_save_path))
async download_bulk_async(team_id, remote_paths, local_save_paths, semaphore=None, caches=None, progress_cb=None, progress_cb_type='size')

Download multiple Files from Team Files.

Parameters:
team_id : int

Team ID in Supervisely.

remote_paths : List[str]

List of paths to Files in Team Files.

local_save_paths : List[str]

List of local save paths.

semaphore : asyncio.Semaphore

Semaphore for limiting the number of simultaneous downloads.

caches=None

List of cache objects for storing files.

progress_cb : tqdm or callable, optional

Function for tracking download progress.

progress_cb_type : Literal["number", "size"], optional

Type of progress callback. Can be “number” or “size”. Default is “size”.

Returns:

None

Return type:

None

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

paths_to_files = [
    "/999_App_Test/ds1/01587.json",
    "/999_App_Test/ds1/01588.json",
    "/999_App_Test/ds1/01587.json"
]
local_paths = [
    "/path/to/save/999_App_Test/ds1/01587.json",
    "/path/to/save/999_App_Test/ds1/01588.json",
    "/path/to/save/999_App_Test/ds1/01587.json"
]
loop = sly.utils.get_or_create_event_loop()
loop.run_until_complete(
    api.file.download_bulk_async(8, paths_to_files, local_paths)
)
download_directory(team_id, remote_path, local_save_path, progress_cb=None)

Download Directory from Team Files.

Parameters:
team_id : int

Team ID in Supervisely.

remote_path : str

Path to Directory in Team Files.

local_save_path : str

Local save path.

progress_cb : tqdm or callable, optional

Function for tracking download progress.

Returns:

None

Return type:

None

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

path_to_dir = "/My_App_Test/ds1"
local_save_path = "/home/admin/Downloads/My_local_test"

api.file.download_directory(9, path_to_dir, local_save_path)
async download_directory_async(team_id, remote_path, local_save_path, semaphore=None, show_progress=True)

Download Directory from Team Files to local path asynchronously.

Parameters:
team_id : int

Team ID in Supervisely.

remote_path : str

Path to Directory in Team Files.

local_save_path : str

Local save path.

semaphore : asyncio.Semaphore

Semaphore for limiting the number of simultaneous downloads.

show_progress : bool

If True show download progress.

Returns:

None

Return type:

None

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

path_to_dir = "/files/folder"
local_path = "path/to/local/folder"

loop = sly.utils.get_or_create_event_loop()
loop.run_until_complete(
    api.file.download_directory_async(9, path_to_dir, local_path)
)
download_input(save_path, unpack_if_archive=True, remove_archive=True, force=False, log_progress=False)

Downloads data for application from input using environment variables. Automatically detects if data is a file or a directory and saves it to the specified directory. If data is an archive, it will be unpacked to the specified directory if unpack_if_archive is True.

Parameters:
save_path : str

path to a directory where data will be saved

unpack_if_archive : Optional[bool]

if True, archive will be unpacked to the specified directory

remove_archive : Optional[bool]

if True, archive will be removed after unpacking

force : Optional[bool]

if True, data will be downloaded even if it already exists in the specified directory

log_progress : bool

if True, progress bar will be displayed

Raises:

RuntimeError

  • if both file and folder paths not found in environment variables

  • if both file and folder paths found in environment variables (debug)

  • if team id not found in environment variables

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

# Application is started...
save_path = "/my_app_data"
api.file.download_input(save_path)

# The data is downloaded to the specified directory.
async download_input_async(save_path, semaphore=None, unpack_if_archive=True, remove_archive=True, force=False, show_progress=False)

Asynchronously downloads data for the application, using a path from file/folder selector. The application adds this path to environment variables, which the method then reads. Automatically detects if data is a file or a directory and saves it to the specified directory. If data is an archive, it will be unpacked to the specified directory if unpack_if_archive is True.

Parameters:
save_path : str

path to a directory where data will be saved

semaphore : asyncio.Semaphore

Semaphore for limiting the number of simultaneous downloads

unpack_if_archive : Optional[bool]

if True, archive will be unpacked to the specified directory

remove_archive : Optional[bool]

if True, archive will be removed after unpacking

force : Optional[bool]

if True, data will be downloaded even if it already exists in the specified directory

show_progress : bool

if True, progress bar will be displayed

Raises:

RuntimeError

  • if both file and folder paths not found in environment variables

  • if both file and folder paths found in environment variables (debug)

  • if team id not found in environment variables

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

# Application is started...
save_path = "/my_app_data"
loop = sly.utils.get_or_create_event_loop()
loop.run_until_complete(
    api.file.download_input_async(save_path)
)

# The data is downloaded to the specified directory.
exists(team_id, remote_path)[source]

Checks if file exists in Team Files / Cloud Storage / Agent.

Parameters:
team_id : int

Team ID in Supervisely.

remote_path : str

Remote path to File in Team Files.

Returns:

True if file exists, otherwise False

Return type:

bool

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

file = api.storage.exists(8, "/999_App_Test/ds1/02163.json") # True
file = api.storage.exists(8, "/999_App_Test/ds1/01587.json") # False
get_directory_size(team_id, path)

Get directory size in the Team Files. If directory is on local agent, then optimized method will be used (without api requests)

Parameters:
team_id : int

Team ID in Supervisely.

path : str

Path to Directory.

Returns:

Directory size in the Team Files

Return type:

int

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

team_id = 9
path = "/My_App_Test/"
size = api.file.get_directory_size(team_id, path)

print(size)
# Output: 3478687
get_free_dir_name(team_id, dir_path)

Adds suffix to the end of the Directory name.

Parameters:
team_id : int

Team ID in Supervisely.

dir_path : str

Path to Directory in Team Files.

Returns:

New Directory name with suffix at the end

Return type:

str

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

new_dir_name = api.file.get_free_dir_name(9, "/My_App_Test")
print(new_dir_name)
# Output: /My_App_Test_001
get_free_name(team_id, path)

Adds suffix to the end of the file name.

Parameters:
team_id : int

Team ID in Supervisely.

path : str

Remote path to file in Team Files.

Returns:

New File name with suffix at the end

Return type:

str

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

file = api.file.get_free_name(8, "/999_App_Test/ds1/02163.json")
print(file)
# Output: /999_App_Test/ds1/02163_000.json
get_info_by_id(id)[source]

This method available only for Team Files.

get_info_by_path(team_id, remote_path)[source]

Gets File information by path in Team Files / Cloud Storage / Agent.

Parameters:
team_id : int

Team ID in Supervisely.

remote_path : str

Remote path to file in Team Files.

Returns:

Information about file.

Return type:

FileInfo

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

file_path = "/999_App_Test/ds1/00135.json"
file_info = api.storage.get_info_by_id(8, file_path)
print(file_info)
# Output: FileInfo(team_id=8,
#                  id=7660,
#                  user_id=7,
#                  name='00135.json',
#                  hash='z7Hv9a7WIC5HIJrfX/69KVrvtDaLqucSprWHoCxyq0M=',
#                  path='/999_App_Test/ds1/00135.json',
#                  storage_path='/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json',
#                  mime='application/json',
#                  ext='json',
#                  sizeb=261,
#                  created_at='2021-01-11T09:04:17.959Z',
#                  updated_at='2021-01-11T09:04:17.959Z',
#                  full_storage_url='http://supervisely.com/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json')
get_json_file_content(team_id, remote_path, download=False)

Get JSON file content.

Parameters:
team_id : int

Team ID in Supervisely.

remote_path : str

Path to JSON file in Team Files.

download : bool, optional

If True, download file in temp dir to get content.

Returns:

JSON file content

Return type:

dict or None

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

file_content = api.file.get_json_file_content()
print(file_content)
get_list_all_pages(method, data, progress_cb=None, convert_json_info_cb=None, limit=None, return_first_response=False)

Get list of all or limited quantity entities from the Supervisely server.

Parameters:
method : str

Request method name

data : dict

Dictionary with request body info

progress_cb : Progress, optional

Function for tracking download progress.

convert_json_info_cb : Callable, optional

Function for convert json info

limit : int, optional

Number of entity to retrieve

return_first_response : bool, optional

Specify if return first response

Returns:

List of entities.

Return type:

List[dict]

get_list_all_pages_generator(method, data, progress_cb=None, convert_json_info_cb=None, limit=None, return_first_response=False)

This generator function retrieves a list of all or a limited quantity of entities from the Supervisely server, yielding batches of entities as they are retrieved

Parameters:
method : str

Request method name

data : dict

Dictionary with request body info

progress_cb : Progress, optional

Function for tracking download progress.

convert_json_info_cb : Callable, optional

Function for convert json info

limit : int, optional

Number of entity to retrieve

return_first_response : bool, optional

Specify if return first response

async get_list_idx_page_async(method, data)

Get the list of items for a given page number. Page number is specified in the data dictionary.

Parameters:
method : str

Method to call for listing items.

data : dict

Data to pass to the API method.

Returns:

List of items.

Return type:

Tuple[int, List[NamedTuple]]

async get_list_page_generator_async(method, data, pages_count=None, semaphore=None)

Yields list of images in dataset asynchronously page by page.

Parameters:
method : str

Method to call for listing items.

data : dict

Data to pass to the API method.

pages_count : int, optional

Preferred number of pages to retrieve if used with a per_page limit. Will be automatically adjusted if the pagesCount differs from the requested number.

semaphore=None

Semaphore for limiting the number of simultaneous requests.

Returns:

List of images in dataset.

Return type:

AsyncGenerator[List[ImageInfo]]

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

method = 'images.list'
data = {'datasetId': 123456}

loop = sly.utils.get_or_create_event_loop()
images = loop.run_until_complete(api.image.get_list_generator_async(method, data))
list(team_id, path, recursive=True, return_type='fileinfo', with_metadata=True, include_files=True, include_folders=True, limit=None)[source]

List of all or limited quantity files from the Team Files or Cloud Storages.

Parameters:
team_id : int

Team ID in Supervisely.

path : str

Path to File or Directory.

recursive : bool

If True return all files recursively.

return_type : str

The specified value between ‘dict’ or ‘fileinfo’. By default: ‘fileinfo’.

with_metadata : bool

If True return files with metadata.

include_files : bool

If True return files infos.

include_folders : bool

If True return folders infos.

limit : int

Limit the number of files returned.

Returns:

List of all Files with information.

Return type:

List[Union[Dict, FileInfo]]

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

team_id = 8

# Option 1. Get information about files from Team Files:
file_path = "/tmp/test_img/"
files = api.storage.list(team_id, file_path)
file = files[0]
print(file.name)
# Output: berries.jpeg

print(files)
# Output: [
#   FileInfo(team_id=8, id=7660, user_id=7, name='00135.json', hash='z7Wv1a7WI...
#   FileInfo(team_id=8, id=7661, user_id=7, name='01587.json', hash='La9+XtF2+...
# ]


# Option 2. Get information from Cloud Storages (S3, Azure, Google Cloud Storage)
file_path = "s3://remote-img-test/test_img/"
# or
file_path = "azure://supervisely-test/test_img/"
# or
file_path = "google://sly-dev-test/test_img/"

files = api.storage.list(team_id, file_path, return_type="dict", limit=2)
print(files)
# Output: [
#     {
#         "type": "file",
#         "name": "berries-01.jpeg",
#         "prefix": "test_img",
#         "path": "azure://supervisely-test/test_img/berries-01.jpeg",
#         "updatedAt": "2024-03-08T16:03:41.000Z",
#         "meta": {
#             "size": 3529930
#         }
#     },
#     {
#         "type": "file",
#         "name": "berries-02.jpeg",
#         "prefix": "test_img",
#         "path": "azure://supervisely-test/test_img/berries-02.jpeg",
#         "updatedAt": "2024-03-08T16:03:38.000Z",
#         "meta": {
#             "size": 1311144
#         }
#     }
# ]
list2(team_id, path, recursive=True)[source]

Method is not implemented. Use api.storage.list instead. Additionally, to get list of files in Team Files you can use api.file.list2.

list_on_agent(team_id, path, recursive=True, return_type='dict')

List of files in the Team Files.

Parameters:
team_id : int

Team ID.

path : str

Path to File or Directory.

recursive : bool

If True return all files recursively.

return_type : str

The specified value between ‘dict’ or ‘fileinfo’. By default: ‘dict’.

Returns:

List of all Files with information.

Return type:

List[Union[Dict, FileInfo]]

listdir(team_id, path, recursive=False)[source]

Method is not implemented. Use api.storage.list instead. Additionally, to get list of files in Team Files you can use api.file.listdir.

load_dotenv_from_teamfiles(remote_path=None, team_id=None, override=False)

Loads .env file from Team Files into environment variables. If remote_path or team_id is not specified, it will be taken from environment variables.

Parameters:
remote_path : str, optional

Path to .env file in Team Files.

team_id : int, optional

Team ID in Supervisely.

override : bool, optional

If True, existing environment variables will be overridden.

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

api.file.load_dotenv_from_teamfiles()
# All variables from .env file are loaded into environment variables.
remove(team_id, path)

Removes a file from the Team Files. If the specified path is a directory, the entire directory (including all recursively included files) will be removed.

Parameters:
team_id : int

Team ID in Supervisely.

path : str

Path in Team Files.

Returns:

None

Return type:

None

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

api.file.remove(8, "/999_App_Test/ds1/01587.json") # remove file
api.file.remove(8, "/999_App_Test/ds1/") # remove folder
remove_batch(team_id, paths, progress_cb=None, batch_size=1000)

Removes list of files from Team Files.

Parameters:
team_id : int

Team ID in Supervisely.

paths : List[str]

List of paths to Files in Team Files.

progress_cb : tqdm or callable, optional

Function for tracking progress.

batch_size : int

Number of files to remove in one request. Default is 1000. Maximum is 20000.

Returns:

None

Return type:

None

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

paths_to_del = [
    "/999_App_Test/ds1/01587.json",
    "/999_App_Test/ds1/01588.json",
    "/999_App_Test/ds1/01587.json"
]
api.file.remove_batch(8, paths_to_del)
remove_file(team_id, path)

Removes file from Team Files.

Parameters:
team_id : int

Team ID in Supervisely.

path : str

Path to File in Team Files.

Returns:

None

Return type:

None

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

api.file.remove_file(8, "/999_App_Test/ds1/01587.json")
rename(old_name, new_name)

Renames file in Team Files

Parameters:
old_name : str

Old File name.

new_name : str

New File name.

Returns:

None

Return type:

None

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

# NotImplementedError('Method is not supported')
upload(team_id, src, dst, progress_cb=None)

Upload File to Team Files.

Parameters:
team_id : int

Team ID in Supervisely.

src : str

Local source file path.

dst : str

Path to File in Team Files.

progress_cb : tqdm or callable, optional

Function for tracking download progress.

Returns:

Information about uploaded file.

Return type:

FileInfo

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

src_path = "/home/admin/Downloads/01587.json"
dst_remote_path = "/999_App_Test/ds1/01587.json"

api.file.upload(8, src_path, dst_remote_path)
async upload_async(team_id, src, dst, semaphore=None, progress_cb=None, progress_cb_type='size')

Upload file from local path to Team Files asynchronously.

Parameters:
team_id : int

Team ID in Supervisely.

src : str

Local path to file.

dst : str

Path to save file in Team Files.

semaphore : asyncio.Semaphore, optional

Semaphore for limiting the number of simultaneous uploads.

progress_cb : tqdm or callable, optional

Function for tracking download progress.

progress_cb_type : Literal["number", "size"], optional

Type of progress callback. Can be “number” or “size”. Default is “size”.

Returns:

None

Return type:

None

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

path_to_file = "/path/to/local/file/01587.json"
path_to_save = "/files/01587.json"
loop = sly.utils.get_or_create_event_loop()
loop.run_until_complete(
    api.file.upload_async(8, path_to_file, path_to_save)
)
upload_bulk(team_id, src_paths, dst_paths, progress_cb=None)

Upload Files to Team Files.

Parameters:
team_id : int

Team ID in Supervisely.

src_paths : List[str]

Local source file paths.

dst_paths : List[str]

Destination paths for Files to Team Files.

progress_cb : tqdm or callable, optional

Function for tracking upload progress.

Returns:

Information about uploaded files.

Return type:

List[FileInfo]

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

src_paths = ["/home/admin/Downloads/01587.json", "/home/admin/Downloads/01588.json","/home/admin/Downloads/01589.json"]
dst_remote_paths = ["/999_App_Test/ds1/01587.json", "/999_App_Test/ds1/01588.json", "/999_App_Test/ds1/01589.json"]

api.file.upload_bulk(8, src_paths, dst_remote_paths)
async upload_bulk_async(team_id, src_paths, dst_paths, semaphore=None, progress_cb=None, progress_cb_type='size', enable_fallback=True)

Upload multiple files from local paths to Team Files asynchronously.

Parameters:
team_id : int

Team ID in Supervisely.

src_paths : List[str]

List of local paths to files.

dst_paths : List[str]

List of paths to save files in Team Files.

semaphore : asyncio.Semaphore, optional

Semaphore for limiting the number of simultaneous uploads.

progress_cb : tqdm or callable, optional

Function for tracking download progress.

progress_cb_type : Literal["number", "size"], optional

Type of progress callback. Can be “number” or “size”. Default is “size”.

enable_fallback : bool, optional

If True, the method will fallback to synchronous upload if an error occurs.

Returns:

None

Return type:

None

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

paths_to_files = [
    "/path/to/local/file/01587.json",
    "/path/to/local/file/01588.json",
    "/path/to/local/file/01589.json"
]
paths_to_save = [
    "/files/01587.json",
    "/files/01588.json",
    "/files/01589.json"
]
loop = sly.utils.get_or_create_event_loop()
loop.run_until_complete(
    api.file.upload_bulk_async(8, paths_to_files, paths_to_save)
)
upload_bulk_fast(team_id, src_paths, dst_paths, semaphore=None, progress_cb=None, progress_cb_type='size', enable_fallback=True)

Upload multiple files from local paths to Team Files in fast mode. Files are uploaded asynchronously. If an error occurs, the method will fallback to synchronous upload.

Parameters:
team_id : int

Team ID in Supervisely.

src_paths : List[str]

List of local paths to files.

dst_paths : List[str]

List of paths to save files in Team Files.

semaphore : asyncio.Semaphore, optional

Semaphore for limiting the number of simultaneous uploads.

progress_cb : tqdm or callable, optional

Function for tracking download progress.

progress_cb_type : Literal["number", "size"], optional

Type of progress callback. Can be “number” or “size”. Default is “size”. “size” is used to track the number of transferred bytes. “number” is used to track the number of transferred files.

enable_fallback : bool, optional

If True, the method will fallback to synchronous upload if an error occurs.

Returns:

None

Return type:

None

upload_directory(team_id, local_dir, remote_dir, change_name_if_conflict=True, progress_size_cb=None, replace_if_conflict=False)

Upload Directory to Team Files from local path.

Parameters:
team_id : int

Team ID in Supervisely.

local_dir : str

Path to local Directory.

remote_dir : str

Path to Directory in Team Files.

change_name_if_conflict : bool, optional

Checks if given name already exists and adds suffix to the end of the name.

progress_size_cb : Progress, optional

Function for tracking download progress.

Returns:

Path to Directory in Team Files

Return type:

str

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

path_to_dir = "/My_App_Test/ds1"
local_path = "/home/admin/Downloads/My_local_test"

api.file.upload_directory(9, local_path, path_to_dir)
async upload_directory_async(team_id, local_dir, remote_dir, change_name_if_conflict=True, progress_size_cb=None, replace_if_conflict=False, enable_fallback=True)

Upload Directory to Team Files from local path. Files are uploaded asynchronously.

Parameters:
team_id : int

Team ID in Supervisely.

local_dir : str

Path to local Directory.

remote_dir : str

Path to Directory in Team Files.

change_name_if_conflict : bool, optional

Checks if given name already exists and adds suffix to the end of the name.

progress_size_cb : Progress, optional

Function for tracking download progress.

replace_if_conflict : bool, optional

If True, replace existing dir.

enable_fallback : bool, optional

If True, the method will fallback to synchronous upload if an error occurs.

Returns:

Path to Directory in Team Files

Return type:

str

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

path_to_dir = "/999_App_Test/ds1"
local_path = "/path/to/local/folder"

api.file.upload_directory(8, local_path, path_to_dir)
upload_directory_fast(team_id, local_dir, remote_dir, change_name_if_conflict=True, progress_cb=None, replace_if_conflict=False, enable_fallback=True)

Upload Directory to Team Files from local path in fast mode. Files are uploaded asynchronously. If an error occurs, the method will fallback to synchronous upload.

Parameters:
team_id : int

Team ID in Supervisely.

local_dir : str

Path to local Directory.

remote_dir : str

Path to Directory in Team Files.

change_name_if_conflict : bool, optional

Checks if given name already exists and adds suffix to the end of the name.

progress_cb : Progress, optional

Function for tracking download progress in bytes.

replace_if_conflict : bool, optional

If True, replace existing dir.

enable_fallback : bool, optional

If True, the method will fallback to synchronous upload if an error occurs.

Returns:

Path to Directory in Team Files

Return type:

str