StorageApi¶
- class StorageApi[source]¶
Bases:
supervisely.api.file_api.FileApiAPI for working with Files and Folders in Team Files and Cloud Storage.
StorageApiobject is immutable.- Parameters
- api : Api
API connection to the server.
- 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() # Pass values into the API constructor (optional, not recommended) # api = sly.Api(server_address="https://app.supervise.ly", token="4r47N...xaTatb") team_id = 8 file_path = "/999_App_Test/" files = api.storage.list(team_id, file_path)
Methods
_convert_info_to_json
Checks if directory exists in Team Files / Cloud Storage / Agent.
Download File from Team Files.
Download File from Team Files.
Download multiple Files from Team Files.
Download Directory from Team Files.
Download Directory from Team Files to local path asynchronously.
download_from_agent- rtype
Downloads data for application from input using environment variables.
Asynchronously downloads data for the application, using a path from file/folder selector.
Checks if file exists in Team Files / Cloud Storage / Agent.
Get directory size in the Team Files.
Adds suffix to the end of the Directory name.
Adds suffix to the end of the file name.
This method available only for Team Files.
Gets File information by path in Team Files / Cloud Storage / Agent.
Get JSON file content.
Get list of all or limited quantity entities from the Supervisely server.
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 the list of items for a given page number.
Yields list of images in dataset asynchronously page by page.
get_url- rtype
NamedTuple FileInfo information about File.
NamedTuple name - FileInfo.
is_on_agentList of all or limited quantity files from the Team Files or Cloud Storages.
Method is not implemented.
list_on_agentMethod is not implemented.
Loads .env file from Team Files into environment variables.
parse_agent_id_and_path- rtype
Removes a file from the Team Files.
Removes list of files from Team Files.
remove_dir- rtype
Removes file from Team Files.
remove_from_agent- rtype
Renames file in Team Files
Upload File to Team Files.
Upload file from local path to Team Files asynchronously.
Upload Files to Team Files.
Upload multiple files from local paths to Team Files asynchronously.
Upload multiple files from local paths to Team Files in fast mode.
Upload Directory to Team Files from local path.
Upload Directory to Team Files from local path.
Upload Directory to Team Files from local path in fast mode.
Attributes
MAX_WAIT_ATTEMPTSMaximum number of attempts that will be made to wait for a certain condition to be met.
WAIT_ATTEMPT_TIMEOUT_SECNumber of seconds for intervals between attempts.
- InfoType¶
alias of
supervisely.api.module_api.FileInfo
- dir_exists(team_id, remote_directory)[source]¶
Checks if directory exists in Team Files / Cloud Storage / Agent.
- Parameters
- Returns
True if directory exists, otherwise False
- Return type
- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
- Returns
None
- Return type
NoneType- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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 : FileCache, optional
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
NoneType- Usage example
import supervisely as sly import asyncio os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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 : List[FileCache], optional
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
NoneType- Usage example
import supervisely as sly import asyncio os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
- Returns
None
- Return type
NoneType- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
NoneType- Usage example
import supervisely as sly import asyncio os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
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 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.- Return type
-
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
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 import asyncio # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication 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.- Return type
- exists(team_id, remote_path)[source]¶
Checks if file exists in Team Files / Cloud Storage / Agent.
- Parameters
- Returns
True if file exists, otherwise False
- Return type
- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
- Returns
Directory size in the Team Files
- Return type
- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
- Returns
New Directory name with suffix at the end
- Return type
- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
- Returns
New File name with suffix at the end
- Return type
- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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_path(team_id, remote_path)[source]¶
Gets File information by path in Team Files / Cloud Storage / Agent.
- Parameters
- Returns
Information about File. See
info_sequence- Return type
FileInfo- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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://supervise.ly/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json')
-
get_json_file_content(team_id, remote_path, download=
False)¶ Get JSON file content.
- Parameters
- Returns
JSON file content
- Return type
dictorNoneType- Usage example
import supervisely as sly api = sly.Api("https://app.supervisely.com", "YourAccessToken") 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
-
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.
-
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_pagelimit. Will be automatically adjusted if thepagesCountdiffers from the requested number.- semaphore :
asyncio.Semaphore, optional Semaphore for limiting the number of simultaneous requests.
- kwargs
Additional arguments.
- Returns
List of images in dataset.
- Return type
AsyncGenerator[List[ImageInfo]]
- Usage example
import supervisely as sly import asyncio os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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))
- static info_sequence()¶
NamedTuple FileInfo information about File.
- 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://supervise.ly/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json')
- static info_tuple_name()¶
NamedTuple name - FileInfo.
-
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. See classes info_sequence and FileInfo
- Return type
class 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() # Pass values into the API constructor (optional, not recommended) # api = sly.Api(server_address="https://app.supervise.ly", token="4r47N...xaTatb") 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.
- Return type
List[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
- Usage example
import supervisely as sly
api = sly.Api.from_env()
api.file.load_dotenv_from_teamfiles() # All variables from .env file are loaded into environment variables.
- Return type
- 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
- Returns
None
- Return type
NoneType- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
- Returns
None
- Return type
NoneType- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
- Returns
None
- Return type
NoneType- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
- Returns
None
- Return type
NoneType- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() # NotImplementedError('Method is not supported')
-
upload(team_id, src, dst, progress_cb=
None)¶ Upload File to Team Files.
- Parameters
- Returns
Information about File. See
info_sequence- Return type
FileInfo- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
NoneType- Usage example
import supervisely as sly import asyncio os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
- Returns
Information about Files. See
info_sequence- Return type
List[FileInfo]- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
NoneType- Usage example
import supervisely as sly import asyncio os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
NoneType
-
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
- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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
- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' 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)
-
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